这是这篇文章的后续问题
我有两个模型:
CarType.cs
//
// Holds types of car - this has a one to many relationship with Car class
//
[Table("tType")]
public class CarType
{
[Key]
public int type_id { get; set; }
public int dealer_id { get; set; }
public string type_name { get; set; }
public string type_desc { get; set; }
public virtual ICollection<Car> Cars { get; set; }
}
Car.cs
//
// Holds actual Cars
//
[Table("tCar")]
public class Car
{
[Key]
public int car_id { get; set; }
public int dealer_id { get; set; }
public int type_id { get; set; }
public int car_order { get; set; }
public string car_name { get; set; }
public virtual ICollection<Rental> Rentals { get; set; }
public virtual CarType CarType { get; set; }
}
我想要一个视图模型,我可以在其中查看汽车类型,以及每个汽车类型类中每种汽车类型的数量,所以我创建了一个视图模型:
public class SearchViewModel
{
[Required]
public DateTime From { get; set; }
public int Nights { get; set; }
public int dealer_id { get; set; }
public IQueryable<CarType> CarTypes { get; set; }
// CarTypes as above, has a one to many relationship with the class Car
}
给定一个预先确定的实际汽车列表(比如 preBookedCars),我想从 ViewObject 中删除汽车列表,例如,如果 CarType 的模型(包括一个 2 多个汽车)看起来像这样:
Mercedes (count = 3)
....Car 1
....Car 2
....Car 3
Ford (count = 3)
....Car 4
....Car 5
....Car 6
Citroen (count = 3)
....Car 7
....Car 8
....Car 9
给定汽车列表,我将如何从 CarType 模型中排除汽车列表 - 例如。
我有一个列表:汽车 1、汽车 4、汽车 8、汽车 9 - 所以我希望上面的模型显示:
Mercedes (count = 2)
....Car 2
....Car 3
Ford (count = 2)
....Car 5
....Car 6
Citroen (count = 1)
....Car 7
我知道它类似于(伪 LINQ):
var freeCars = (db context).CarTypes
.Cars
.Except(preBookedCars)
感谢您的任何帮助,
标记