简体   繁体   中英

Dynamic Linq - String.Split

It appears that Dynamic Linq doesn't implement the String.Split method.

Is there a way achieve the same results with Dynamic Linq ?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM