LINQ query with two joins that worked in EF 6 gives an error in EF 7

I have a LINQ query that works in an EF 6 (Code First) project. Now I moved the code to EF 7, and this request now throws an exception: ArgumentException: the property 'Int32 ID' is not defined for type 'X.Models.Domain.MadeChoice'

Request:

var madeChoices = from res in X.Instance.Residence join room in X.Instance.Room on res.ID equals room.Residence.ID join madeChoice in X.Instance.MadeChoice on room.ID equals madeChoice.Room.ID where res.ID == residence.ID select room.MadeChoices; 

MadeChoice Class:

 public class MadeChoice { public virtual int ID { get; set; } [Required] public virtual ChoiceGroup Choicegroup { get; set; } [Required] public virtual Room Room { get; set; } [Required] public virtual Item Item { get; set; } } 

Room Class:

 public class Room { public virtual int ID { get; set; } public string Name { get; set; } public string Description { get; set; } public virtual Residence Residence { get; set; } public virtual RoomType RoomType { get; set; } public virtual List<MadeChoice> MadeChoices { get; set; } // Constructors: public Room() { this.MadeChoices = new List<MadeChoice>(); } } 

Class of residence:

 public class Residence { public int ID { get; set; } public string ApartmentNumber { get; set; } public static IQueryable<List<MadeChoice>> GetMadeChoices(Residence residence) { var madeChoices = from res in X.Instance.Residence join room in X.Instance.Room on res.ID equals room.Residence.ID join madeChoice in X.Instance.MadeChoice on room.ID equals madeChoice.Room.ID where res.ID == residence.ID select room.MadeChoices; System.Diagnostics.Debug.Write("MadeChoices.Count: "); System.Diagnostics.Debug.WriteLine(madeChoices.Count()); foreach (var madechoice in madeChoices) { System.Diagnostics.Debug.Write("MadeChoice.Count: "); System.Diagnostics.Debug.WriteLine(madechoice.Count()); } return madeChoices; } // Navigational properties: public virtual List<Room> Rooms { get; set; } public virtual ResidenceType ResidenceType { get; set; } public virtual List<Tenant> Tenants { get; set; } public virtual List<PeriodResidenceDeadline> PeriodResidenceDeadline { get; set; } // Constructors: public Residence() { this.Rooms = new List<Room>(); this.Tenants = new List<Tenant>(); this.PeriodResidenceDeadline = new List<PeriodResidenceDeadline>(); } } 

Initially, the identifier was not virtual, but it did not affect the error. The database looks the same as in EF 6. This relationship is a one-to-many relationship. I am using EF 7.0.0-rc1-final.

Any clues?

Thanks in advance,

Peter

+5
source share
1 answer

As the EF team said, EF Core RC1 does not handle complex subtypes (see their roadmap here https://github.com/aspnet/EntityFramework/wiki/Roadmap#in-progress for the request)

For queries, this will be processing in RTF EF Core 1.0.

In the meantime, you can use one of the solutions that I list here: Clear mapping of EF Core to the internal properties of the object (the problem is the same for display)

+1
source

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


All Articles