gpt4 book ai didi

c# - Entity Framework 4.1 Linq Contains 和 StartsWith

转载 作者:太空狗 更新时间:2023-10-29 17:45:11 25 4
gpt4 key购买 nike

我正在使用 Entity Framework Code First。我想根据 List 对象从数据库中查询实体。这适用于包含,但我如何将它与 StartsWith 结合使用?

这是我的代码:

List<string> values = new List<string>();
values.Add("A");
values.Add("B");
context.Customer.Where(c => values.Contains(c.Name)).ToList();

我如何查询所有以 A 或 B 开头的客户?

最佳答案

这应该在内存中工作,但我不确定它是否可以被 EF 翻译成 SQL:

context.Customer.Where(c => values.Any(s => c.Name.StartsWith(s))).ToList();

关于c# - Entity Framework 4.1 Linq Contains 和 StartsWith,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8838292/

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