我有以下查询哪些工作正常。但是,它不适用于需要的联接查询。LINQ to Entities条件where子句
var ra = from c in _context.Wxlogs
select c;
if (year == "2011")
{
ra = (IQueryable<Wxlog>)(from c in _context.Wxlogs
where c.LogYear == year
&& (SqlFunctions.DatePart("Month", c.LogDate2) == m3)
&& c.LogTime.Contains("23:59")
orderby c.LogDate2
let LogDate = c.LogDate2
select new {
LogDate,
c.Rain_today
});
}
else if (year != "2011")
{
ra = (IQueryable<Wxlog>)(from c in _context.Wxlogs
where c.LogYear == year
&& c.LogMonth == mm
&& c.LogTime.Contains("08:59")
orderby c.LogDate2
let LogDate = EntityFunctions.AddDays(c.LogDate2, -1)
select new {
LogDate,
c.Rain_today
});
}
因此,我一直在试图嵌入else条件(something like this answer by Whaheed)没有任何运气。
任何帮助,将不胜感激。
不工作怎么样?不会给你你期望的数据,抛出错误,或? – Tim
连接出现此错误:“连接子句中某个表达式的类型不正确,在对”加入“的调用中,类型推断失败。 – Corretto