我有以下查詢哪些工作正常。但是,它不適用於需要的聯接查詢。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