Entity Framework 7 Include() Order

asp.net-core-mvc entity-framework-core

Question

In MVC6/EF7, should there be a difference in an order I use Include() to include navigation properties into a query?

This query works

var vt = await db.VehicleTypes
            .Include(t => t.Photos)
            .Include(t => t.VehicleModels)
            .ThenInclude(m => m.Units)
            .Include(t => t.Rates)
            .ThenInclude(r => r.DailyPrice.Currency)
            .ToListAsync()

But this query throws an exception at ToListAsync()

var vt = await db.VehicleTypes
            .Include(t => t.Photos)
            .Include(t => t.Rates)
            .ThenInclude(r => r.DailyPrice.Currency)
            .Include(t => t.VehicleModels)
            .ThenInclude(m => m.Units)
            .ToListAsync()

The error is

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index

I understand it's Beta, there may be bugs. In this case - is it a bug or a designed behavior?

Popular Answer

Looks like a bug; the order shouldn't matter. Would you mind creating an issue?




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why