I'm trying to load a list of product identifier Label
s (i.e. names of product identifiers, such as "EAN", "Product number", etc.) from ProductIdentifiers
with this query:
ICollection<ProductIdentifierInType> typeIds =
_context.ProductIdentifiersInTypes
.Include(t => t.Identifier.Label)
.OrderBy(o => o.SortOrder).ToList();
VS gives me intellisense for t.Identifier.Label
. The solution compiles fine. This is the runtime error I get:
InvalidOperationException: The property 'Label' is not a navigation property of entity type 'ProductIdentifier'. The 'Include(string)' method can only be used with a '.' separated list of navigation property names.
Here are the relevant model classes:
public class ProductIdentifierInType
{
public int Id { get; set; }
public int ProductTypeId { get; set; }
public int SortOrder { get; set; }
public ProductIdentifier Identifier { get; set; }
public ProductType Type { get; set; }
}
public class ProductIdentifier
{
public int Id { get; set; }
public string Label { get; set; }
public int SortOrder { get; set; }
public ICollection<ProductIdentifierInType> TypeIdentifiers { get; set; }
}
My DbContext:
public class MyStoreContext : DbContext // IdentityDbContext
{
public MyStoreContext(DbContextOptions options) : base(options) { }
// some unrelated tables ...
public DbSet<ProductIdentifierInType> ProductIdentifiersInTypes { get; set; }
public DbSet<ProductIdentifier> ProductIdentifiers { get; set; }
// some more, unrelated tables ...
}
I have tried inheriting from IdentityDbContext
like the solution in this question, but that didn't make any difference.
What is wrong?