【发布时间】:2016-09-27 13:37:29
【问题描述】:
我有 2 个查询是查询同一个表但具有不同的参数,我想合并为一个, 查询 1
//ToDo refactor
int myDayOfWeek = 0;
DateTime dt = DateTime.Today;
myDayOfWeek = (int)dt.DayOfWeek;
var todaysLecture = (from c in _context.LectureGigs.Where(g => g.IsWeekLy == true && (int)g.Days == (myDayOfWeek))
select c).ToList();
//results Ok 1 result
查询 2
var upCommingLecture = _context.LectureGigs
.Include(g => g.Artist).Include(g => g.Genre)
.Where(g => g.DateTime > DateTime.Now && !g.IsCanceled);
//results Ok 2 result
我想创建的查询
var upCommingLecture = _context.LectureGigs
.Include(g => g.Artist).Include(g => g.Genre).Where(g => g.IsWeekLy == true && (int)g.Days == (myDayOfWeek))
.Where(g => g.DateTime > DateTime.Now && !g.IsCanceled);
//Error none but 0 result
我也试过了
var upCommingLecture = _context.LectureGigs
.Include(g => g.Artist).Include(g => g.Genre)
.Where(g => g.DateTime > DateTime.Now && !g.IsCanceled && g.IsWeekLy==true &&(int)g.Days==(myDayOfWeek));
//Error none but 0 result
【问题讨论】:
-
你不能使用 where 子句来使用 OR 条件吗?这样你就可以把你的两个陈述合二为一了?
-
嗨,在我的查询中,我想同时获得结果(q1 和 q2 -3 项总数)而不是其中一个查询的结果
标签: c# asp.net-mvc linq linq-to-sql