私は複雑で(むしろハッキーな)動的SQLクエリをLINQクエリに変換しようとしています。LINQの結果がなくなりました
私はこれまで、次のLINQクエリを持っている:
var results = (
from c in Customers
from d in MonthCalendar
join f in Facilities on c.CustomerCode equals f.CustomerCode
join p in ProjectedCashFlows on f.FacilityId equals p.FacilityId into pj
from p in pj.DefaultIfEmpty()
where d.ExpectedYear == currentYear
&& f.FacilityStatusId == 1
&& (p.ExpectedYear == null || d.ExpectedYear == p.ExpectedYear)
&& (p.ExpectedMonth == null || d.ExpectedMonth == p.ExpectedMonth)
&& c.PrimaryArmId == userId
&& (p.ProjectedCashFlowStatusId == null || p.ProjectedCashFlowStatusId != 4)
select new
{
CustomerCode = c.CustomerCode,
CustomerName = c.CustomerName,
FacilityId = f.FacilityId,
FacilityDescription = f.FacilityProductDescription,
FacilityCurrency = f.FacilityCurrencyId,
FacilityLimit = f.Limit,
ExpectedYear = d.ExpectedYear,
ExpectedMonth = d.ExpectedMonth,
ExpectedAmount = p == null ? 0 : (double)p.ExpectedAmount
}
);
私はFacilities
テーブルと1対多の関係を持っていCustomer
テーブルから詳細を取得しようとしています。私はその後、私が午前問題は、クエリに関係なく、任意の値がProjectedCashFlows
テーブルに存在するかどうかのすべてCustomer
とFacilites
情報を返すべきであるということですProjectedCashFlows
に配置されているすべての詳細を取得しようとしています。
残念ながら、このクエリは実行していません。ProjectedCashFlows
テーブルにファシリティが存在する場合、情報はCustomer
とFacilities
という情報のみを返します。
私はMonthCalender
テーブルを使用して、その年の各月を一覧表示しています。
関連するテーブル情報は、次のとおりです。
お客様
- CustomerCode
- CustomerNameの
- PrimaryArmId
施設
- CustomerCode
- FacilityId
- FacilityCurrencyId
- FaciliyLimit
- FacilityDescription
ProjectedCashFlows
- CustomerCode
- FacilityId
- ExpectedYear
- ExpectedMonth
- ExpectedAmount
- ProjectedCashFlowStatusId
MonthsCalendar
- ExpectedMonth
- ExpectedYear
私はしかしFacilities
表に4行を持っている顧客を持っている例として、それらが表示されていないので、これらの施設の2はProjectedCashFlows
テーブルには表示されません。エントリがProjectedCashFlows
に存在しない場合
それは、CalendarMonths
テーブルからExpectedMonth & ExpectedYearを取るExpectedAmountに0を返し、Facilities
テーブルからFacilityIdを使用する必要があります。
あなたはおそらく私はLINQを使い始めたばかりです。
誰でも正しい方向に私を突きつけられますか?