查询Lambda语法的表达式?

时间:2013-11-21 02:13:53

标签: linq entity-framework lambda

如何将此查询表达式更改为lambda表达式:

var dataUser = from cm in ConsumerName
                  join c in Consumer on cm.ConsumerId equals c.Id
                  join cua in ConsumerAccount on cm.ConsumerId equals cua.ConsumerId
                  join bd in  BankDetail on cm.ConsumerId equals bd.ConsumerId
                  join cpm in CardPayment on cm.ConsumerId equals cpm.ConsumerId 
                  where cm.ConsumerId == consumerId
                  select new { AccountNumber=bd.AccountNumber,CardNumber= cpm.CardNumber,  Name = cm.FirstName + "  " + cm.MiddleName +  " " + cm.LastName, Email = c.Email, AccountId = cua.AccountId };

1 个答案:

答案 0 :(得分:1)

简单,由Resharper自动转换

var dataUser =
    ConsumerName.Join(Consumer, cm => cm.ConsumerId, c => c.Id, (cm, c) => new { cm, c })
        .Join(ConsumerAccount, @t => cm.ConsumerId, cua => cua.ConsumerId, (@t, cua) => new { @t, cua })
        .Join(BankDetail, @t => cm.ConsumerId, bd => bd.ConsumerId, (@t, bd) => new { @t, bd })
        .Join(CardPayment, @t => cm.ConsumerId, cpm => cpm.ConsumerId, (@t, cpm) => new { @t, cpm })
        .Where(@t => cm.ConsumerId == consumerId)
        .Select(
            @t =>
            new
                {
                    AccountNumber = bd.AccountNumber,
                    CardNumber = cpm.CardNumber,
                    Name = cm.FirstName + "  " + cm.MiddleName + " " + cm.LastName,
                    Email = c.Email,
                    AccountId = cua.AccountId
                });