【发布时间】:2020-04-12 18:48:41
【问题描述】:
我已经搜索了互联网,但无法找到适合我的具体案例的内容。
这是我的模型:
public class Unit
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UnitID { get; set; }
public string Name { get; set; }
public int UnitStatusID { get; set; }
public List<ReservationUnit> ReservationUnits { get; set; }
}
public class ReservationUnit
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ReservationUnitID { get; set; }
[Required]
public int ReservationID { get; set; }
public Reservation Reservation { get; set; }
[Required]
public int UnitID { get; set; }
public Unit Unit { get; set; }
public decimal Amount { get; set; }
public bool AmountIsTaxInclusive { get; set; }
public bool IsFixedRate { get; set; }
}
public class Reservation
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ReservationID { get; set; }
public int ReservationStatusID { get; set; }
public List<ReservationUnit> Units { get; set; }
}
我需要找到:
- statusid == 1 的所有单位
- 对于所有这些单位,reservationid == 1 的所有预订
我可以获取单元并且可以选择所有的预订单元...但我无法过滤预订以获取包含的预订项目。谁能指出我正确的方向?这是我尝试过的:
var unitQuery =
db
.Units
.Where(x => x.UnitStatusID == 1 || x.UnitStatusID == 4)
.Include(o => o.ReservationUnits.Where(p => p.Reservation.ReservationStatusID == 1))
.ToList();
这给了我以下错误:
System.ArgumentException: '包含路径表达式必须引用在类型上定义的导航属性。对引用导航属性使用虚线路径,对集合导航属性使用 Select 运算符。 (参数'路径')'
【问题讨论】:
-
尝试分开
Include和where进行预订。
标签: c# linq entity-framework-core blazor