2016-03-01 22 views
5

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

+0

Forse aggiungendo [Key] sulla vostra proprietà ID vi aiuterà? – cdie

+0

@cdie No, non ha aiutato :( –

+0

Potresti postare i tuoi mapping? – cdie

risposta

1

Come squadra EF ha detto, EF core RC1 non gestisce complessi sottotipi (vedere la loro tabella di marcia qui https://github.com/aspnet/EntityFramework/wiki/Roadmap#in-progress per Query)

Per l'esecuzione di query, questo sarà gestito nella versione RTM EF Core 1.0.

Nel frattempo, è possibile utilizzare una delle soluzioni che enumerare qui: EF Core fluent mapping to inner object properties (il problema è lo stesso per la mappatura)

+0

Un commento per il record in quanto potrebbe aiutare altri lettori: Sembra che questo errore si verifichi quando l'istruzione select seleziona un Elenca e non un singolo oggetto. –

Problemi correlati