在C#LINQ中使用SQL LIKE运算符 [英] Use SQL LIKE operator in C# LINQ
本文介绍了在C#LINQ中使用SQL LIKE运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用C#建立查询.对于整数和字符串字段,大小写非常简单.对于日期字段,我正在使用以下查询:
I am building up a query in C#. For integer and string fields, case is quite simple. For date fields, I am using following query:
list.Where("myDateColumn >= DateTime(2017,1,20)");
如何在LINQ中执行以下SQL LIKE查询?
How I can perform following SQL LIKE query in LINQ?
select * from table where myTextColumn LIKE '%abc%';
推荐答案
Linq中的赞"有很多可能性:
There are lots of possibilities for Like in Linq:
对于LIKE'%abc%';
For LIKE '%abc%';
list.Where(x => x.myTextColumn.Contains('abc'));
对于喜欢的"abc%";
For LIKE 'abc%';
list.Where(x => x.myTextColumn.StartWith('abc'));
对于LIKE'%abc';
For LIKE '%abc';
list.Where(x => x.myTextColumn.EndsWith('abc'));
更新::如果您还需要添加日期比较,则可以执行以下操作:
Updates : If you need to add Date comparison as well means you can do like the following:
DateTime date2Compare = new DateTime(2017, 1, 20);
list.Where(x => myDateColumn >= date2Compare && x.myTextColumn.Contains('abc'));
这篇关于在C#LINQ中使用SQL LIKE运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文