Dynamic Linq - String.Split

元气小坏坏 提交于 2019-12-23 20:15:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!