EF5到EF6升级 – 导航属性被破坏

我使用nuget将EF5升级到EF6,并在某处为我的解决方案引入了一个重大变化。 我在运行我的一个unit testing时发现了这个(虽然它影响了一切)。 在每个测试中,我通过这样做:

// warm up EF. using (var context = new ReportingDbContext()) { context.Database.Initialize(false); // <-- boom! } // init the service _inventoryService = new InventoryService(); 

它抛出了我这个例外:

 The property 'EmployeeID' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection where T is a valid entity type. 

奇怪的是,EF5上的一切都只是极好的。 我去寻找我的模型(我有一堆),并发现EmployeeID生活的每个地方。 他们都看起来像这样:

 [Table("mytablename")] public class CSATEntity { [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] public int CSATID { get; set; } // foreign keys public int ClientID { get; set; } public int ContactID { get; set; } // nav props [ForeignKey("ClientID")] public virtual CompanyEntity CompanyEntity { get; set; } [ForeignKey("EmployeeID")] public virtual EmployeeEntity EmployeeEntity { get; set; } ... more props 

例外情况并未说明哪个模型被顶起,或者所有模型都是。 追捕这个的最好方法是什么?

尝试更改命名空间

  System.Data.Objects.ObjectContext to System.Data.Entity.Core.Objects.ObjectContext System.Data.Objects to System.Data.Entity.Core.Objects 

请查看此MSDN页面http://msdn.microsoft.com/en-us/data/dn469466 。 它解释了如何升级到Entity Framework 6