My entity classes:
public class Unit
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int? UnitID { get; set; }
public string Name { get; set; }
[Required]
public int? ManufacturerID { get; set; }
// More fields
public Manufacturer Manufacturer { get; set; }
}
public class Manufacturer
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int? ManufacturerID { get; set; }
public string Name { get; set; }
}
My query:
return await DbContext.Unit.AsNoTracking().Include(r => r.Manufacturer)
.Select(r => new
{
UnitID = r.UnitID,
UnitName = r.Name,
ManufacturerName = r.Manufacturer.Name // Using Manufacturer
}).ToListAsync();
The warning message:
...|WARN|Microsoft.EntityFrameworkCore.Query|The Include operation for navigation '[r].Manufacturer' is unnecessary and was ignored because the navigation is not reachable in the final query results. See https://go.microsoft.com/fwlink/?linkid=850303 for more information...
I am using Manufacturer.name in new anonymous so It means navigation [r].Manufacturer must be used.
Why Entity Framework Core warns the message? Is am doing wrong? Thanks!
.Select
statement which returns a non-entity type), the original entity won't be used and only the navigation properties used within it are really required. It would otherwise lead to bad performance to do additional joins (thats usually what happens on include) for non used nav properties