【发布时间】:2014-03-14 06:35:03
【问题描述】:
我使用 nuget 将 EF5 升级到 EF6,并在某处为我的解决方案引入了重大更改。我在运行我的一个单元测试时发现了这一点(尽管它会影响一切)。在每次测试中,我都会这样做:
// 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<T> 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
该例外没有说明哪个型号被顶起,或者是否所有型号都被顶起。追捕这个问题的最佳方法是什么?
【问题讨论】:
标签: c# entity-framework upgrade relationship