[英]How do i write a linq query to get list of records where id in (1,2,3,8,23,45)
I want to select the list of records for n ids, i have the list of ids and i want to use it at once as we write in sql query select * from abc where id in(3,4,6,7,8,14).我想选择 n 个 id 的记录列表,我有 id 列表,我想在编写 sql 查询时立即使用它 select * from abc where id in(3,4,6,7,8, 14)。 Like this i want to write the linq query.
像这样我想编写 linq 查询。 i wrote something like this:
我写了这样的东西:
var mylist = (from log in context.mylog
where logIdList.Contains(log.Id)
select log).ToList();
but this is giving me error.但这给了我错误。
Note: logIdList is the list of Ids.注意:logIdList 是 Id 列表。
Do you want something like:你想要这样的东西:
var myList = from log in context.mylog
join id in logIdList on log.Id equals id
select log;
Check weather this solution works.检查天气此解决方案是否有效。 I have not tried it.
我没试过。 So not sure.
所以不确定。
var MyList = Context.MyLog.Where(x => LogIdList.Contains(x.Id)).ToList();
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.