您现在的位置是:首页 > 电脑 > 

多表上的MVC EF问题(MVC EF issues on multiple table)

2025-07-20 12:04:59
多表上的MVC EF问题(MVC EF issues on multiple table) 我正在开发一个包含个表的数据库 旅行模型: [Key] public int TripId { get; set; } [ForeignKey("Driver")] public int DriverId { get; s
多表上的MVC EF问题(MVC EF issues on multiple table)

我正在开发一个包含个表的数据库

旅行模型:

[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 Driverame { 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 Passengerame { 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.Conventi.Remove<IncludeMetadataConvention>(); }

我收到以下错误:

无法检查模型兼容性,因为模型中未包含EdmMetadata类型。 确保已将IncludeMetadataConvention添加到DbModelBuilder约定中。

关于这个问题的解决方案? 谢谢!

i am developing a database with 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 Driverame { 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 Passengerame { 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.Conventi.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 conventi.

Any soluti on this issue? Thanks!

最满意答案

尝试在Global.asax的Application_Start事件处理程序中添加对Database.SetInitializer方法的调用:

Database.SetInitializer<Contextame>(null);

其中Contextame是自定义DbContext类的名称。

Try adding a call to the Database.SetInitializer method in the Application_Start event handler of your Global.asax:

Database.SetInitializer<Contextame>(null);

where Contextame is the name of your custom DbContext class.

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/diannao/697383.html

相关标签:无
上传时间: 2023-08-27 09:50:16
留言与评论(共有 13 条评论)
本站网友 泰州房产网
15分钟前 发表
Try adding a call to the Database.SetInitializer method in the Application_Start event handler of your Global.asax
本站网友 zune
8分钟前 发表
Column(Order = 0)] public int TripId { get; set; } public virtual Trip Trip { get; set; } And last passenger model
本站网友 断牙
22分钟前 发表
Model compatibility cannot be checked because the EdmMetadata type was not included in the model. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventi. Any soluti on this issue? Thanks! 最满意答案 尝试在Global.asax的Application_Start事件处理程序中添加对Database.SetInitializer方法的调用: Database.SetInitializer<Contextame>(null); 其中Contextame是自定义DbContext类的名称
本站网友 梅花三弄
17分钟前 发表
Try adding a call to the Database.SetInitializer method in the Application_Start event handler of your Global.asax
本站网友 甘家口
2分钟前 发表
Column(Order = 0)] public int TripId { get; set; } public virtual Trip Trip { get; set; } And last passenger model
本站网友 先锋霉素
1分钟前 发表
Column(Order = 0)] public int TripId { get; set; } public virtual Trip Trip { get; set; } And last passenger model
本站网友 luguan
25分钟前 发表
Database.SetInitializer<Contextame>(null); where Contextame is the name of your custom DbContext class.
本站网友 g2a
8分钟前 发表
public class LiveGreenContext
本站网友 打美白针
12分钟前 发表
因为模型中未包含EdmMetadata类型
本站网友 张琼玲
12分钟前 发表
[Key] public int DriverId { get; set; } public string Driverame { get; set; } [ForeignKey("Trip")
本站网友 眉山社区
7分钟前 发表
多表上的MVC EF问题(MVC EF issues on multiple table) 我正在开发一个包含个表的数据库 旅行模型: [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 Driverame { get; set; } [ForeignKey("Trip")
本站网友 色与性
4分钟前 发表
Column(Order = 1)] public int TripId { get; set; } public virtual Trip Trip { get; set; } 附: public class LiveGreenContext