我有两个实体
match.params
,其中包含GasStationSummary
FuelSummary
我有加油站:
public class GasStationSummary
{ ...
public virtual List<FuelSummary> FuelSummary { get; set; } = new List<FuelSummary>();
}
public class FuelSummary
{
public int GsSummaryId { get; set; }
public int FuelId { get; set; }
...
}
我想为加油站提供一个FuelType列表,其中FuelId等于this.repository.ListAsync().Include(x => x.FuelSummary)
有没有一种使用实体框架的方法?
答案 0 :(得分:2)
您可以使用投影
this.repository.ListAsync().Where(u => u.FuelSummary.Any(e => e.FuelId == 1)
.Select(x => new
{
x,
Fuels = x.FuelSummary.Where(e => e.FuelId == 1)
});
使用IncludeFilter
或库Entity Framework Plus