Select all columns from one table and 1 column from another

c# entity-framework entity-framework-core

Question

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.

1
0
2/22/2019 2:51:08 PM

Accepted Answer

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}
2
2/22/2019 3:04:14 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow