6

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

The 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;

The 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; }
}

The 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>();
    }
}

The Residence 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>();
    }
}

Originally, the ID was not virtual but it didn't affect the error. The database looks as in EF 6. The relationships are one-to-many. I use EF 7.0.0-rc1-final.

Any hints?

Thanks in advance,

Peter

Peter Lindgren
  • 173
  • 1
  • 10

1 Answers1

2

As EF team said, EF Core RC1 doesn't handle complex sub-types (see their roadmap here https://github.com/aspnet/EntityFramework/wiki/Roadmap#in-progress for Query)

For querying, this will be handle in the EF Core 1.0 RTM version.

In the meantime, you can use one of the solution I enumerate here : EF Core fluent mapping to inner object properties (the problem is the same for mapping)

Community
  • 1
  • 1
cdie
  • 4,014
  • 4
  • 34
  • 57
  • A comment for the record as it might help other readers: It seems as this error occurs when the select statement selects a List and not a single object. – Peter Lindgren Mar 04 '16 at 08:40