Dynamic Linq - String.Split

Dynamic Linq does not seem to implement the String.Split method.

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

+3
source share
2 answers

Dynamic Linq supports String.Split and also calls other methods such as .net, 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)");

He was able to convert a string to an expression tree, but since SQL does not have any string splitting operation, it throws an error if you run it in SQL

+1
source

Reply 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 great in LINQPad

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

0
source

Source: https://habr.com/ru/post/1773699/


All Articles