嗨,有人可以帮忙吗?尝试在我的视图中显示有关Carmodels的数据时,出现上述错误
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CarId { get; set; }
[Required]
public string Registration { get; set; }
[Required]
public virtual CarModels Model { get; set; }
[Required]
public string RegistrationYear { get; set; }
[Required]
public string ChassisNumber { get; set; }
[Required]
public int RegistrationId { get; set; }
这是功能
public static List<Cars> GetRegistrationCars(int registration)
{
List<Cars> registrationCars = new List<Cars>();
using (var db = new EventsContext())
{
registrationCars = db.Cars.Where(c => c.RegistrationId == registration).ToList();
}
return registrationCars.ToList();
}
啊哈终于想通了感谢您的建议
public static List<Cars> GetRegistrationCars(int registration)
{
List<Cars> registrationCars = new List<Cars>();
using (var db = new FerrariEventsContext())
{
registrationCars = db.Cars.Include(m=> m.Model).Where(c => c.RegistrationId == registration).ToList();
}
return registrationCars;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句