Option 1:
Change the line...
fields.Add("or (LastName + \", \" + MiddleName + \" \" + FirstName).Contains(@1)");
...to
fields.Add("or string.Concat(LastName, \", \", MiddleName, \" \", FirstName).Contains(@1)");
Option 2:
Open the
Dynamic.cs
file of the Dynamic LINQ library, search for"GenerateStringConcat"
in that file. You should find this method:Expression GenerateStringConcat(Expression left, Expression right) { return Expression.Call( null, typeof(string).GetMethod("Concat", new[] { typeof(object), typeof(object) }), new[] { left, right }); }
Change the
object
parameter types tostring
, that is:Expression GenerateStringConcat(Expression left, Expression right) { return Expression.Call( null, typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) }), new[] { left, right }); }
Keep in mind that Dynamic LINQ is not a special "LINQ-to-Entities library", but a general library for IQueryable
. There might be Queryable providers that support string.Concat(object, object)
with the general object
parameter, but LINQ-to-Entities does not. It only supports the string
parameter versions of string.Concat
. Looking through the Dynamic LINQ file when GenerateStringConcat
is actually called (only once) I believe the change above is safe as long as you only want to use the library with LINQ-to-Entities/Entity Framework.
Edit
Option 1 does not work because Concat
gets more than four string parameters in the example. It only works up to four parameters because string.Concat
has an overload with four explicit string
parameters. It doesn't seem to be possible to use the overload with the array parameter params string[]
in Dynamic LINQ.