I have three tables and I have used edmx designer to add associations between them. Below is how they are linked.
(table1) Loans - (table 2) Investor : Many to One relationship (Table2) Investor - (Table3) InvestorInfo : One to Many relationship
I want to get [1] Total loans count sold to one investor, [2] Investor name and [3] investor's service fee which is stored in Table3 at idx = 2005 for each investor ("investor id & idx" is primary key of table3 - InvestorInfo table).
How do I do that in below query? I am forced to select 'FirstOrDefault()' to access any column in Table3 (See commented lines). If I use FirstOrDefualt, I get a record where idx = 1 and not 2005.
var loanPurchaseData = (from cd in entity.Table1
//where cd.Table2.Table3.Select(x => x.IDX == 2005)
//where cd.ULDD_SET_POOLS.ULDD_SET_POOLDT.FirstOrDefault().SORT_ID == 2005
group cd by new { cd.Table4.PurchaseDate, cd.Number } into grp
select new
{
investor = grp.FirstOrDefault().Investor,
no_of_loans = grp.Count(),
sort_id = grp.FirstOrDefault().Table2.Table3.FirstOrDefault().SORT_ID,
service_fee_rate = grp.FirstOrDefault().Table2.Table3.FirstOrDefault().DT_REAL_PERC_VALUE
}).ToList();