I am using System.Linq.Dynamic
library for generating dynamic where condition on IQueryable
collection. Can anyone list the list of operation supported by this library? I do only know = and Cont开发者_开发技巧ains. Can i use "IN
, Like
, Not Like
etc..."?
The library is used to create dynamic linq, so I would not expect it to support the sql-operators you mention. Looking at the code it seems to support a subset of the methods in System.Linq.Enumerable.
var code = File.ReadAllText("dynamic.cs");
var strings = Regex.Matches(code, "\"(\\w*)\"").Cast<Match>()
.Select(m => m.Groups[1].Value);
var methods = typeof(System.Linq.Enumerable).GetMethods(BindingFlags.Public
| BindingFlags.Static).Select(mi => mi.Name);
string.Join(", ", strings.Intersect(methods)).Dump();
Give: Where, Select, OrderBy, OrderByDescending, ThenBy, ThenByDescending, Take, Skip, GroupBy, Any, Count, Min, Max, Concat
Update: I now found the documentation, LinqSamples\DynamicQuery\Dynamic expression.html, in the download. I think you'll find what you are looking for in the operators-section. (And the above can be confirmed in the IQueryable Extension Methods-section.)
The System.Linq.Dynamic library looks at operators like == > < >= etc. It can also execute any function that a given property has access to.
Here's System.Linq.Dynamic example for "LIKE"
myQueryable.Where(
"customer.name.StartsWith(@0) AND customer.lastName.EndsWith(@1)","B","E");
This is equivalent to:
"select .... from .... WHERE customer.name LIKE 'B%' AND customer.name LIKE '%E'"
The library can call any function that System.String has access to in this example. On a side node, it already uses they keyword "IN" and if you want to say "NOT LIKE" just say "!customer.name.StartsWith(...)"
精彩评论