如何使用动态LINQ(System.Linq.Dynamic)进行LIKE操作?
谁能告诉我如何使用 System.Linq.Dynamic 使用 LIKE 运算符?
我需要在动态 where 查询 中添加多个 LIKE
表达式,
/*
var query =
db.Customers.
Where("CityName Like @0 or CityName Like @1", "London", "USA")
*/
var query =
db.Customers.
Where("CityName Like @0 or CityName Like @1%", "London", "USA")
谢谢堆
Can any body tell me how can I use a LIKE operator using System.Linq.Dynamic?
I need to add more than one LIKE
expression in my dynamic where query
/*
var query =
db.Customers.
Where("CityName Like @0 or CityName Like @1", "London", "USA")
*/
var query =
db.Customers.
Where("CityName Like @0 or CityName Like @1%", "London", "USA")
thanks heaps
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试简单地使用“CityName.Contains(@1)”,这将转换为正确的 lambda,因为它是对可访问类型的方法调用。
类似于:
刚刚使用动态库附带的示例应用程序对其进行了测试,它生成了 LIKE 运算符
Try using simply "CityName.Contains(@1)" this will convert to the proper lambda since its a method invocation on an accessible type.
something like:
Just tested it with the sample app that comes with the dynamic library and it generates the LIKE operator
您可以使用
.StartsWith()、
.EndsWith()
和.Contains()
这将生成带有尾随、前导和周围通配符的 LIKE SQL分别。不知道如何生成带有嵌入通配符的语句。You can use
.StartsWith(),
.EndsWith()
and.Contains()
which will generate LIKE SQL with trailing, leading and surrounding wildcards respectively. Don't know of a way to generate a statement with an embedded wildcard tho.这将允许在整数字段上使用
LIKE
运算符:This will allow the
LIKE
operator on integer fields:只需添加更多 where 子句
,但上面的查询将创建它:
你想要的
要使用 Dynamic Created 或语句,您可以使用 predicatebuilder 确实有很多
您可以使用的功能...
http://www.albahari.com/nutshell/predicatebuilder .aspx
Just add more where clauses
but the above query will create it :
you want
To use Dynamic Created or statements you can use predicatebuilder there's really alot
of functionality there that you can use...
http://www.albahari.com/nutshell/predicatebuilder.aspx
你可以试试这个。
you can try this.