Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq-搜索表记录包含搜索字符串的任何字母_C#_Linq - Fatal编程技术网

C# Linq-搜索表记录包含搜索字符串的任何字母

C# Linq-搜索表记录包含搜索字符串的任何字母,c#,linq,C#,Linq,我正在使用下面的Linq查询成功搜索具有FirstName=“abcxyz”的表记录 db.People.Where(p => searchString.Contains(p.FirstName).ToList(); 但是我想搜索包含FirstName=“abcxyz” 就像在SQL中一样- 任何建议都会对您有所帮助。看看SQL,您需要的是: p.FirstName.Contains(searchString) 所以你的问题是: db.People.Where(p => p.F

我正在使用下面的
Linq
查询成功搜索具有
FirstName=“abcxyz”
的表记录

db.People.Where(p => searchString.Contains(p.FirstName).ToList();
但是我想搜索包含
FirstName=“abcxyz”

就像在SQL中一样-


任何建议都会对您有所帮助。

看看SQL,您需要的是:

p.FirstName.Contains(searchString)
所以你的问题是:

db.People.Where(p => p.FirstName.Contains(searchString)).ToList();

看看SQL,您需要的是:

p.FirstName.Contains(searchString)
所以你的问题是:

db.People.Where(p => p.FirstName.Contains(searchString)).ToList();

您可以在LINQ中使用以下方法,在SQL中使用LIKE运算符获取数据

例如:

1) 如果你想从我们使用的字母开始获取数据

在SQL中:-

select * from People where firstname LIKE '%abc';
在林克:-

db.People.Where(p => p.firstname.StartsWith(abc));
2) 如果您想获取包含我们正在使用的任何字母的数据

在SQL中

select * from people where firstname LIKE '%abc%';
林克

db.people.where(p => p.Contains(abc));
db.people.where(p => p.firstname.EndsWith(abc));
3) 如果你想得到以我们正在使用的字母结尾的数据

在SQL中

select * from people where firstname LIKE '%abc';
林克

db.people.where(p => p.Contains(abc));
db.people.where(p => p.firstname.EndsWith(abc));

您可以在LINQ中使用以下方法,在SQL中使用LIKE运算符获取数据

例如:

1) 如果你想从我们使用的字母开始获取数据

在SQL中:-

select * from People where firstname LIKE '%abc';
在林克:-

db.People.Where(p => p.firstname.StartsWith(abc));
2) 如果您想获取包含我们正在使用的任何字母的数据

在SQL中

select * from people where firstname LIKE '%abc%';
林克

db.people.where(p => p.Contains(abc));
db.people.where(p => p.firstname.EndsWith(abc));
3) 如果你想得到以我们正在使用的字母结尾的数据

在SQL中

select * from people where firstname LIKE '%abc';
林克

db.people.where(p => p.Contains(abc));
db.people.where(p => p.firstname.EndsWith(abc));

缺少与OP相同的括号,但您的想法是正确的。:)缺少与OP相同的括号,但您的想法是正确的。:)