在Linq查询中,我需要按日期和本地、日期或本地筛选约会。
因此,如果GivenDate和GivenLocal不是null,则需要通过GivenDate和GivenLocal进行筛选:
appointments.Where(x => x.Date == x.GivenDate && x.Local == x.GivenLocal)如果GivenDate为null,则筛选将由本地完成:
appointments.Where(x => x.Local == x.GivenLocal)如果GivenLocal为null,则按日期进行筛选:
appointments.Where(x => x.Date == x.GivenDate)是否可以用一个查询来完成这个任务,而不是使用IF语句和3个查询?
发布于 2014-07-30 21:09:32
appointments.Where(x =>
(x.GivenDate == null || x.Date == x.GivenDate) &&
(x.GivenLocal == null || x.Local == x.GivenLocal) && )发布于 2014-07-30 21:16:53
appointments.Where(x => ((x.GivenDate != null & x.GivenLocal!!= null & x.Date == x.GivenDate && x.Local == x.GivenLocal) \x_ (x.GivenDate == _ null & x.Local == _( == x.GivenLocal )]_(x.GivenDate == _ null &x.Local==x.GivenLocal)\x{e76f}\\{e76f}\\{e76f}\
https://stackoverflow.com/questions/25046918
复制相似问题