gpt4 book ai didi

linq - 如何在 Linq 查询中使用 Like?

转载 作者:行者123 更新时间:2023-12-04 10:05:55 24 4
gpt4 key购买 nike

我如何在 LINQ 中使用 Like 查询....
在 sql 中,例如..

名字像='苹果';

谢谢..

最佳答案

使用普通的 .NET 方法。例如:

var query = from person in people
where person.Name.StartsWith("apple") // equivalent to LIKE 'apple%'
select person;

(或 EndsWithContains 。)LINQ to SQL 会将这些转换为适当的 SQL。

这也适用于点表示法 - 查询表达式没有什么神奇之处:
// Will find New York
var query = cities.Where(city => city.Name.EndsWith("York"));

关于linq - 如何在 Linq 查询中使用 Like?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3139590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com