Update EF5 to EF6 - Navigation Properties Broken

I used nuget to upgrade EF5 to EF6, and somewhere the change was changed for my solution. I discovered this when running one of my unit tests (this all affects everything). In each test, I initialize this:

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

This throws me this exception:

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.

The strange thing, everything was just a peach on EF5. I went hunting through my models (I have a bunch) and found wherever EmployeeID lives. They all look like this:

[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

The exception does not take into account which model is hacked, or all of them. What is the best way to find this?

+4
source share
1 answer

Try changing the namespace from

 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

0

Source: https://habr.com/ru/post/1527004/


All Articles