MVC3 EF 在多个表上出现问题
我正在开发一个包含 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加对 Database.SetInitializerGlobal.asax 的
Application_Start
事件处理程序中的 a> 方法:其中
ContextName
是自定义 DbContext 类。Try adding a call to the Database.SetInitializer method in the
Application_Start
event handler of yourGlobal.asax
:where
ContextName
is the name of your custom DbContext class.