简体   繁体   English

动态Linq - String.Split

[英]Dynamic Linq - String.Split

It appears that Dynamic Linq doesn't implement the String.Split method. 似乎Dynamic Linq没有实现String.Split方法。

Is there a way achieve the same results with Dynamic Linq ? 有没有办法使用Dynamic Linq获得相同的结果?

Dynamic Linq does support String.Split and also calling other .net type methods as shown below Dynamic Linq支持String.Split并且还调用其他.net类型方法,如下所示

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 它能够将字符串转换为表达式树,但由于SQL没有任何字符串拆分操作,如果在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 以下在LINQPad中工作得很好

from z in ("4,3,5,2,1".Split(',').AsEnumerable())
  select z

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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