LINQ根据日期数组查询记录
我有一个表(我正在使用实体模型)并使用 LINQ 查询过滤该表,该查询工作正常。 现在我想根据日期数组过滤记录。我无法在日期数组上实施 IN 子句,
filteredList = leadsNewAndScheduled.Where(lead =>
(LeadTypeIDs.Contains(lead.TYPE_ID.ToString()) ||
LeadTypeIDs == string.Empty) &&
(priorityIDs.Contains(lead.PRIORITY_ID.ToString()) ||
priorityIDs == string.Empty) &&
(((lead.EXPIRED_ON <= dateExpiry ||
Convert.ToDateTime(lead.EXPIRED_ON) == DateTime.Today.Date) &&
lead.STATUS_ID == (int)Enumerations.LeadStatus.New) ||
lead.STATUS_ID == (int)Enumerations.LeadStatus.Active) &&
(lead.START_TIME IN (arrAppointmentDates))
).ToList();
我希望您能帮助我
(lead.START_TIME IN (arrAppointmentDates))
提前致谢。
I have a table (I am using Entity Model) and filtered that table using LINQ query which is working fine.
Now I want to filter the records on the basis of array of dates. I am not able to implement IN clause on array of dates
filteredList = leadsNewAndScheduled.Where(lead =>
(LeadTypeIDs.Contains(lead.TYPE_ID.ToString()) ||
LeadTypeIDs == string.Empty) &&
(priorityIDs.Contains(lead.PRIORITY_ID.ToString()) ||
priorityIDs == string.Empty) &&
(((lead.EXPIRED_ON <= dateExpiry ||
Convert.ToDateTime(lead.EXPIRED_ON) == DateTime.Today.Date) &&
lead.STATUS_ID == (int)Enumerations.LeadStatus.New) ||
lead.STATUS_ID == (int)Enumerations.LeadStatus.Active) &&
(lead.START_TIME IN (arrAppointmentDates))
).ToList();
I want your help in following
(lead.START_TIME IN (arrAppointmentDates))
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 谓词构建器
编写不带日期条件的查询,例如
然后写入
但是请注意,如果您使用实体框架时,您需要在实体集上调用 AsExpandable(),然后再对其应用谓词,如下所示:
Use Predicate Builder
Write your query without the date condition like
Then write
However please note that if you're using Entity Framework you need to call AsExpandable() on the entity set before applying predicates on it like so:
我在声明日期列表然后在 LINQ 查询中应用 contains 子句时解决了这个问题。
例子:
I solved this problem while declaring list of dates and then applying contains clause in LINQ query.
example: