Joel:

The call to SOUNDEX is exactly as I said. Nothing else is required. On 
LingExtensionMethodAttribute you can pass an alternative "real" name for 
the function on the database, if you want it to be different from the .NET 
method. 
Like I said previously, to achieve what you want, you need to create a 
MySQL function, which you can call from LINQ.

RP

On Friday, June 6, 2014 5:49:36 PM UTC+1, Joel Hervén wrote:
>
> I can successfully implement the Soundex function. Not exactly in the same 
> easy way as you descripe, is the LingExtensionMethodAttribute just supposed 
> to tell NHibernate to use an SQL method with the exact same name as the C# 
> extension? I really think it should be that easy in a good design but 
> atleast I can´t get that to work instead of the attribute I can override 
> this method and I will have a working Soundex function (after some 
> registration is done)
>
> public override HqlTreeNode BuildHql(MethodInfo method, Expression 
> targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder 
> treeBuilder, IHqlExpressionVisitor visitor)
>         {
>             return treeBuilder.MethodCall("SOUNDEX", new[] 
>                   { 
>                     visitor.Visit(arguments[1]).AsExpression()
>                   });
>         }
>  
> This works, the problem with MATCH() AGAINST() is that it´s basically two 
> method calls that works together and I´m not able to pass two methods to 
> the MethodCall function.
>
>
> Den fredagen den 6:e juni 2014 kl. 16:23:13 UTC+2 skrev Ricardo Peres:
>>
>> Yes:
>>
>> [LinqExtensionMethod]public static String Soundex(this String input)
>> {
>>      throw new NotImplementedException();
>> }
>>
>>
>> And you can call it like this (in SQL Server, because of the SOUNDEX 
>> function, but can be adapted to any server):
>>
>> var soundexName = session.Query<Customer>().Select(x => 
>> x.Name.Soundex()).First();
>>
>>
>> Let me know if this helps!
>>
>> RP
>>
>>
>> On Friday, June 6, 2014 1:38:16 PM UTC+1, Gunnar Liljas wrote:
>>>
>>> No, it's possible to create custom SQL with it as well, since you can 
>>> register custom functions. Not sure about this particular syntax though.
>>>
>>> /g
>>>
>>> On 5 jun 2014, at 20:54, Ricardo Peres <[email protected]> wrote:
>>>
>>> AFAIK, this method only works for translating custom extensions into 
>>> HQL. Since HQL does not support MATCH...AGAINST, there's nothing you can do.
>>> One possible alternative could possibly be writing a custom function in 
>>> MySQL that would wrap MATCH...AGAINST and calling it from LINQ. That is 
>>> possible.
>>>
>>> RP
>>>
>>>
>>> On Thursday, June 5, 2014 8:41:49 AM UTC+1, Joel Hervén wrote:
>>>>
>>>> I´ve tried to write a LINQ extension that executes the MySQL function 
>>>> MATCH(...,...) AGAINST(...). But I have not been able to translate it into 
>>>> appropriate HQL because of the "two functions" syntax. 
>>>>
>>>> To have something to look at I wrote this method
>>>>
>>>> public override HqlTreeNode BuildHql(MethodInfo method, Expression 
>>>> targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder 
>>>> treeBuilder, IHqlExpressionVisitor visitor)
>>>>         {
>>>>             var e1 = treeBuilder.MethodCall("MATCH", new[] 
>>>>                   { 
>>>>                     visitor.Visit(arguments[0]).AsExpression(), 
>>>>                   });
>>>>
>>>>             var e2 = treeBuilder.MethodCall("AGAINST", new[] 
>>>>                   { 
>>>>                     visitor.Visit(arguments[1]).AsExpression(),
>>>>                   });
>>>>
>>>>             return
>>>>                 treeBuilder.Equality(e1, e2);
>>>>         }
>>>>
>>>> The Equality method is obviously not the correct thing here but it will 
>>>> generate the SQL "MATCH(....)+AGAINST(....)" which is very close to 
>>>> correct 
>>>> except the + sign that shouldn´t be there. I have looked at the 
>>>> HqlTreeBuilder many times but I can´t find a working method to just add up 
>>>> the methods like needed here.
>>>>
>>>> So next thing was to look at the HqlTreeBuilder and try to extend with 
>>>> an alternative
>>>>
>>>> public class HqlDoubleMethod : HqlBooleanExpression
>>>>     {
>>>>         public HqlDoubleMethod(IASTFactory factory, HqlExpression lhs, 
>>>> HqlExpression rhs)
>>>>             : base(0, "", factory, lhs, rhs)
>>>>         {
>>>>         }
>>>>     }
>>>>
>>>> Calling this method instead of Equality results in a 
>>>> RewriteEmptyStreamException rule b
>>>>
>>>>
>>>> Is it possible to implement this kind of function without modifying the 
>>>> Nhibernate-core?
>>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "nhusers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/nhusers.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to