FailedUnitTest
FailedUnitTest

Reputation: 1800

Select all columns from one table and 1 column from another

I have the following query in linq:

(from creditCard in DbSet
join rank in base.dataContext.ProductVerticalRanks on creditCard.ProductVerticalReferenceId equals rank.ProductVerticalReferenceId
 where rank.ClientId == clientId
 orderby rank.PreferredOrder
 select creditCard)
 .Include(creditCard => creditCard.ProductVerticalCompany)
 .Include(creditCard => creditCard.Labels);

But now I have a new requirement, I need to add a column 'rank.PreferredOrder' from table 'rank' into the result, is there an easy way of doing this without making a massive 'select' statement, because there are around 20-30 fields in creditCard alone.

Upvotes: 0

Views: 470

Answers (1)

mxmissile
mxmissile

Reputation: 11681

I dont have your model in front of me, so can't confirm this or not, but you can use an anonymous object like this:

from creditCard in DbSet
join rank in base.dataContext.ProductVerticalRanks on 
    creditCard.ProductVerticalReferenceId equals rank.ProductVerticalReferenceId into g
where rank.ClientId == clientId
orderby rank.PreferredOrder
select new {Card = creditCard, Ranks = g}

Upvotes: 2

Related Questions