gpt4 book ai didi

c# - LINQ to SQL是否支持t-sql "in"语句

转载 作者:行者123 更新时间:2023-11-30 13:16:17 25 4
gpt4 key购买 nike

我不知道如何更好地描述标题(所以请随意更改)但我想在 LINQ to SQL 中生成以下语句的等价物:

select * from products where category in ('shoes','boots')

这些字段本质上将来自查询字符串(比这更安全但为了便于解释)即

string[] myfields = request.querystring["categories"].split(',');

谢谢

最佳答案

是的,您使用包含:

db.Products.Where(product => myFields.Contains(product.Category))

又名

from product in db.Products
where myFields.Contains(product.Category)
select product

关于c# - LINQ to SQL是否支持t-sql "in"语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1300266/

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