c# - LINQ Join on multiple columns with different record using extension method syntax -
this question has answer here:
sorry, if question doesn't make sense. let me explain.
i have existing sql query below:
select t1.portfolio, t1.valuedate currentvaluedate, t1.differencepercent currentdp, t2.valuedate previousvaluedate, t2.differencepercent previousdp, case when t1.differencepercent = t2.differencepercent 1 else 0 end ischange [accountingdata].[dbo].[navrec_navsummary] t1 join [accountingdata].[dbo].[navrec_navsummary] t2 on t1.portfolio = t2.portfolio , t2.valuedate = dateadd(day, case datename(weekday, t1.valuedate) when 'sunday' -2 when 'monday' -3 else -1 end, datediff(day, 0, t1.valuedate))
so basically, i'm interested in displaying portfolio's along column tells whether portfolio's differencepercent
value has changed value same portfolio on previous business day.
i'm trying translate same sql query linq using extension method syntax. however, right i'm trying make self join using portfolio property , valuedate of today's portfolio , valuedate of same portfolio on previous business date.
var result = navlist.join(navlist, outer => new { outer.portfolio, outer.valuedate }, inner => new { inner.portfolio, pd = inner.valuedate.previousbusinessdate() }, (outer, inner) => new { outer, inner });
[previousbusinessdate() extension method returns datetime]
here, error:
the type arguments method 'system.linq.enumerable.join(system.collections.generic.ienumerable, system.collections.generic.ienumerable, system.func, system.func, system.func)' cannot inferred usage. try specifying type arguments explicitly.
can me understand problem , solutions.
the problem here
outer => new { outer.portfolio, outer.valuedate }, inner => new { inner.portfolio, pd = inner.valuedate.previousbusinessdate() },
you projecting anonymous types, , need match exactly. in order match, anonymous types must have same signatures, include both property names , type.
in case didn't specify explicitly of property names, above equivalent to
outer => new { portfolio = outer.portfolio, valuedate = outer.valuedate }, inner => new { portfolio = inner.portfolio, pd = inner.valuedate.previousbusinessdate() },
see difference? second member in first line called valuedate
while in second - pd
.
just replace pd
valuedate
, problem solved (for now).
Comments
Post a Comment