问题
It appears that Dynamic Linq doesn't implement the String.Split method.
Is there a way achieve the same results with Dynamic Linq ?
回答1:
Dynamic Linq does support String.Split and also calling other .net type methods as shown below
var query =
db.Customers.Where("City.Split(\"abc\".ToCharArray()).Length == 1 and Orders.Count >= @1", "London", 10).
OrderBy("CompanyName").
Select("New(CompanyName as Name, Phone)");
It was able to convert the string to expression tree but as SQL doesn't have any string split operation it throws error if you run it on SQL
回答2:
Answer to comment below:
string teststring = "one, two, three";
var x = from string z in (teststring.Split(',').AsEnumerable())
where z.Trim() == "two"
select z;
What exactly do you want to do? The following works just fine in LINQPad
from z in ("4,3,5,2,1".Split(',').AsEnumerable())
select z
来源:https://stackoverflow.com/questions/4127781/dynamic-linq-string-split