LINQ to SQL(基于3个表插入事实表)

时间:2018-09-06 21:02:37

标签: c# linq-to-sql linq-to-entities left-join

我无法使用以下联接。 想法是从AceBiMonthlyDaos中找到任何新的组合(AumProductId和IdClient),如果分别在工具和财务帐户的引用表中存在AumProductId和IdClient,则在具有唯一ID的投资表中创建条目。

var result = (from AceBi in context.AceBiMonthlyDaos
                  join Inst in context.Instruments 
                      on AceBi.AumProductId equals Inst.AceId 
                  join FinAcct in context.FinancialAccounts 
                      on AceBi.IdClient equals FinAcct.AceClientId
                  join Invst in context.Investments 
                      on new { Inst.Id, FinAcct.Id } equals { Invst.InstrumentId, Invst.FinaAcctId} into pair                                       
                      from InvestmentDao in pair.DefaultIfEmpty()

1 个答案:

答案 0 :(得分:0)

var query = (from AceBi in context.AceBiMonthlyDaos
                         join Inst in context.Instruments on AceBi.AumProductId equals Inst.AceId
                         join FinAcct in context.FinancialAccounts on AceBi.IdClient equals FinAcct.AceClientId
                         join Invst in context.Investments on new { instrumentId = Inst.Id, finAccountId = FinAcct.Id } equals new { instrumentId = Invst.InstrumentId, finAccountId = Invst.FinAcctId }
                         into pair
                         from Invst in pair.DefaultIfEmpty()
                         select new { Inst, FinAcct, Invst }).Distinct();