3

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

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

ljm
  • 31
  • 1
  • 2

2 Answers2

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

Ankur
  • 33,367
  • 2
  • 46
  • 72
0

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

Hogan
  • 69,564
  • 10
  • 76
  • 117
  • // how do I evaluate this in Dynamic Linq to find if it contains the substring 'two' ? string teststring = "(\"one, two, three\".Split(','))"; – ljm Nov 08 '10 at 20:42
  • Review this to understand the context of my question. http://aspalliance.com/1569_Dynamic_LINQ_Part_1_Using_the_LINQ_Dynamic_Query_Library – ljm Nov 08 '10 at 21:12
  • If you have an IQueryable collection there are better ways to dynamically compose expressions: http://www.albahari.com/nutshell/predicatebuilder.aspx – Preston Guillot Nov 08 '10 at 21:29
  • @ljm : From the link I see what you mean. If you post code that you want to work using that library I might be able to show you a work-around. – Hogan Nov 08 '10 at 22:02