我正在开发一个包含3个表的数据库
旅行模型:
[Key] public int TripId { get; set; } [ForeignKey("Driver")] public int DriverId { get; set; } public virtual Driver Driver { get; set; } public string StartingPoint { get; set; } public string Destination { get; set; } public DateTime TimeDepart { get; set; } public int SeatAvailable { get; set; } public virtual ICollection<Driver> Drivers { get; set; } public virtual ICollection<Passenger> Passengers { get; set; }司机型号:
[Key] public int DriverId { get; set; } public string DriverName { get; set; } [ForeignKey("Trip"), Column(Order = 0)] public int TripId { get; set; } public virtual Trip Trip { get; set; }最后一位乘客型号:
[Key] public int PassengerId { get; set; } public string PassengerName { get; set; } [ForeignKey("Trip"), Column(Order = 1)] public int TripId { get; set; } public virtual Trip Trip { get; set; }附:
public class LiveGreenContext: DbContext { public DbSet<Trip> Trips { get; set; } public DbSet<Driver> Drivers { get; set; } public DbSet<Passenger> Passengers { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); }我收到以下错误:
无法检查模型兼容性,因为模型中未包含EdmMetadata类型。 确保已将IncludeMetadataConvention添加到DbModelBuilder约定中。
关于这个问题的解决方案? 谢谢!
i am developing a database with 3 tables
Trip Model:
[Key] public int TripId { get; set; } [ForeignKey("Driver")] public int DriverId { get; set; } public virtual Driver Driver { get; set; } public string StartingPoint { get; set; } public string Destination { get; set; } public DateTime TimeDepart { get; set; } public int SeatAvailable { get; set; } public virtual ICollection<Driver> Drivers { get; set; } public virtual ICollection<Passenger> Passengers { get; set; }Driver model:
[Key] public int DriverId { get; set; } public string DriverName { get; set; } [ForeignKey("Trip"), Column(Order = 0)] public int TripId { get; set; } public virtual Trip Trip { get; set; }And last passenger model:
[Key] public int PassengerId { get; set; } public string PassengerName { get; set; } [ForeignKey("Trip"), Column(Order = 1)] public int TripId { get; set; } public virtual Trip Trip { get; set; }With:
public class LiveGreenContext: DbContext { public DbSet<Trip> Trips { get; set; } public DbSet<Driver> Drivers { get; set; } public DbSet<Passenger> Passengers { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); }And i get the following error:
Model compatibility cannot be checked because the EdmMetadata type was not included in the model. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions.
Any solutions on this issue? Thanks!
最满意答案
尝试在Global.asax的Application_Start事件处理程序中添加对Database.SetInitializer方法的调用:
Database.SetInitializer<ContextName>(null);其中ContextName是自定义DbContext类的名称。
Try adding a call to the Database.SetInitializer method in the Application_Start event handler of your Global.asax:
Database.SetInitializer<ContextName>(null);where ContextName is the name of your custom DbContext class.
更多推荐
发布评论