0

How can I change this query expression to lambda expression:

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 };
2
  • With a lot of anonymous types. I recommend against it. Why do you want to do this anyway? Commented Nov 21, 2013 at 5:53
  • Standard comment: ORMs are not a replacement for SQL. If you need that many joins 'd be better off creating a view and or stored procedure and map the results. Or you should convert the joins to EF association mappings Commented Nov 21, 2013 at 7:07

1 Answer 1

1

Simple, auto-converted by 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
                });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.