【问题标题】:MVC3 EF issues on multiple table多个表上的 MVC3 EF 问题
【发布时间】:2012-02-08 08:19:32
【问题描述】:

我正在开发一个包含 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 约定中。

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

【问题讨论】:

  • 你有初始化设置吗?

标签: c# linq asp.net-mvc-3 entity-framework-4 entity-framework-4.1


【解决方案1】:

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

Database.SetInitializer<ContextName>(null);

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 1970-01-01
    • 2012-09-22
    • 2018-02-02
    • 2016-09-06
    • 2011-07-22
    相关资源
    最近更新 更多