英文:
Best way to find list items whose date is in another date list in Lambda Expression
问题
I have a list of dates:
我有一个日期列表:
List<DateTime> dates;
And I need those date values to be the ones in the following list that I am going to get ("x.Date" value).
我需要这些日期值是我接下来要获取的列表中的值("x.Date" 值)。
var response = myObject
.Where(x => x.UserId == userId
&& dates.Contains(x.Date))
.Select(x => new
{
x.Id,
x.Quantity,
x.Date
})
.OrderBy(x => x.Id)
.ToList();
英文:
I have a list of dates:
List<DateTime> dates;
And I need those date values to be the ones in the following list that I am going to get ("x.Date" value).
var response = myObject
.Where(x => xUserId == userId
&& Date = x.Date == //this must be the dates values
.Select(x => new
{
x.Id,
x.Quantity,
x.Date
})
.OrderBy(x => x.Id)
.ToList();
答案1
得分: 1
Use Where
... Contains
:
var response = myObject
.Where(x => xUserId == userId && dates.Contains(x.Date))
...
英文:
Use Where
... Contains
:
var response = myObject
.Where(x => xUserId == userId && dates.Contains(x.Date))
...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论