簡體   English   中英

EF5到EF6升級 - 導航屬性被破壞

[英]EF5 to EF6 upgrade - navigation properties are broken

我使用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

例外情況並未說明哪種型號已經升級,或者所有型號都是。 追捕這個的最好方法是什么?

嘗試更改命名空間

 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM