C# 从一个表中选择所有列,从另一个表中选择1列

C# 从一个表中选择所有列,从另一个表中选择1列,c#,entity-framework,entity-framework-core,C#,Entity Framework,Entity Framework Core,我在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 creditCar

我在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);

但是现在我有了一个新的要求,我需要在结果中添加一个列“rank.PreferredOrder”,从表“rank”到结果中,有没有一种简单的方法可以做到这一点,而不必做大量的“select”语句,因为仅信用卡中就有大约20-30个字段

我面前没有您的模型,因此无法确认这一点,但您可以使用以下匿名对象:

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}

我面前没有您的模型,因此无法确认这一点,但您可以使用以下匿名对象:

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}

你的模型是一对多对吗?一张信用卡对应多个等级?没错你的模式是一对多对吧?一张信用卡到多个等级?没错,我想我得分两步来做。因为此查询是针对以下对象返回的:IQueryable creditCardQuery=query…不,不,我想我必须分两步执行。因为此查询是针对以下对象返回的:IQueryable creditCardQuery=query…不,它不是