c# - LINQ Join DbFunction.AddDays vs. DateTime.AddDays -
i have below linq query has simple logic self join collection on 2 date columns. date of 1 table matched previous business date of same table. below linq join query:
var count = dbcontext.navsummaries.join(dbcontext.navsummaries, current => new { current.portfolio, pd = current.valuedate }, //previous => new { previous.portfolio, pd = sqlfunctions.datepart("dw", previous.valuedate) == 1 ? previous.valuedate.adddays(-3) : sqlfunctions.datepart("dw", previous.valuedate) == 0 ? previous.valuedate.adddays(-2) : previous.valuedate.adddays(-1) }, previous => new { previous.portfolio, pd = sqlfunctions.datepart("dw", previous.valuedate) == 1 ? dbfunctions.adddays(previous.valuedate, -3) : sqlfunctions.datepart("dw", previous.valuedate) == 0 ? dbfunctions.adddays(previous.valuedate, -2) : dbfunctions.adddays(previous.valuedate, -1) }, (outer, inner) => new { outer, inner })
for above syntax visual studio gives me following error:
the type arguments method 'system.linq.queryable.join(system.linq.iqueryable, system.collections.generic.ienumerable, system.linq.expressions.expression>, system.linq.expressions.expression>, system.linq.expressions.expression>)' cannot inferred usage. try specifying type arguments explicitly.
when interchange commented syntax 'previous' innerkeyselector, code builds throws below runtime exception:
linq entities not recognize method 'system.datetime adddays(double)' method, , method cannot translated store expression.
...which understandable. made me replace datetime.adddays dbfunctions.adddays. however, have no clue why compile time error thrown join extension , fix it.
Comments
Post a Comment