Ho una query LINQ che funziona in un progetto EF 6 (Code First). Ora ho migrato il codice per EF 7, e questa query ora genera un'eccezione: ArgumentException: proprietà 'Int32 ID' non è definito per il tipo 'X.Models.Domain.MadeChoice'La query LINQ con due join che ha funzionato in EF 6 dà errore in EF 7
La query:
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;
La classe MadeChoice:
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; }
}
La classe camera:
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>();
}
}
Il Reside nce class:
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>();
}
}
In origine, l'ID non era virtuale ma non ha influito sull'errore. Il database appare come in EF 6. Le relazioni sono uno-a-molti. Io uso EF 7.0.0-rc1-final.
Eventuali suggerimenti?
Grazie in anticipo,
Peter
Forse aggiungendo [Key] sulla vostra proprietà ID vi aiuterà? – cdie
@cdie No, non ha aiutato :( –
Potresti postare i tuoi mapping? – cdie