开发者

F# Power Pack Linq Issue

I have a simple function that makes use of the F# power pack to convert a quotation into a linq expression. The function is:

let toLinq (exp : Expr<'a -> 'b>) =
    let linq = exp.ToLinqExpression()
    let call = linq :?> MethodCallExpression
    let lambda = call.Arguments.[0] :?> LambdaExpression
    Expression.Lambda<Func<'a, 'b>>(lambda.Body, lambda.Parameters)

I use this function to create expressions that are consumed by a C# library that uses linq to sql 开发者_如何学Goto query a database. For example I might build an expression like:

    let test = toLinq (<@fun u -> u.FirstName = "Bob"@> : Expr<Account->bool>)

and pass it to a method like:

public IEnumerable<T> Find(Expression<Func<T, bool> predicate)
{
        var result = Table.OfType<T>();         
        result = result.Where(predicate)                                    
        var resultArray = result.ToArray();            
        return resultArray;
}

This was working as designed in verion 1.9.9.9 of the power pack. However it no longer works in the latest version of the power pack. The error I recieve is Method 'Boolean GenericEqualityIntrinsic[String](System.String, System.String)' has no supported translation to SQL.

I took a look at the changes to the power pack and it seems that the linq expression that is built using the new version makes use of GenericEqualityIntrinsic for comparing the property's value with the constant, whereas in version 1.9.9.9 it made use of String.op_Equality for comparison.

Is this a correct understanding of the issue? How do I make use of the new version of the power pack to convert quotations to linq expressions that can be consumed by a c# library that uses linq to sql?


Does explicitly calling

System.String.op_Equality(s1,s2)

work?


You can try the quotation as:

<@fun u -> u.FirstName.Equals("Bob")@>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜