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

问题描述 投票:1回答:1

我无法使用以下加入。想法是从AceBiMonthlyDaos中找到任何新的(AumProductId和IdClient)组合,以在具有唯一ID的投资表中创建条目,如果这些AumProductId和IdClient分别存在于工具和金融账户的参考表中。

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()
c# linq-to-sql linq-to-entities left-join
1个回答
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();
© www.soinside.com 2019 - 2024. All rights reserved.