You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Worklog {
public Guid Id { get; set; }
public Guid ContactFieldValueId { get; set; }
[ForeignKey("ContactFieldValueId")]
public virtual ContactFieldValue ContactFieldValue { get; set; }
// some other columns
}
public class ContactFieldValue {
public Guid Id { get; set; }
public Guid FieldValueId { get; set; }
[ForeignKey("FieldValueId")]
public virtual FieldValue FieldValue { get; set; }
// some other columns
}
public class FieldValue {
public Guid Id { get; set; }
public string Value { get; set; }
// some other columns
}
And I making a query:
var worklogs = await db.Worklogs
.Where(x => worklogIds.Contains(x.Id)) // it's List<Guid> with ~1000 values
.Include(x => x.ContactFieldValue)
.ThenInclude(cf => cf.FieldValue)
.Select(x => new
{
x.Id, // and some other fields from Worklogs
ContactFieldValueFieldValue = x.ContactFieldValue.FieldValue.Value
})
.OrderBy(x => x.Time)
.ThenBy(x => x.Id)
.ToListAsync();
So, I'm selecting some fields from first (Worklog) and one from third (FieldValue) entities.
The issue
I have two problems:
I see warning in logs: The Include operation for navigation: 'x.ContactFieldValue.FieldValue' was ignored because the target navigation is not reachable in the final query results. - this is not true, because I'm selecting Value from it.
Generated SQL SELECT include all columns from ContactFieldValue and all from FiledValue - despite I requested only one:
SELECT
[x].[Id],
[x].[Comment], [x].[ContactFieldValueId], [x].[IssueId], [x].[ScriptVersionId], [x].[Time], [x].[UserId],
[x.ContactFieldValue].[Id],
[x.ContactFieldValue].[FieldValueId],
// all columns from [x.ContactFieldValue] - why???
[x.ContactFieldValue.FieldValue].[Id],
[x.ContactFieldValue.FieldValue].[Value],
// all other columns from FieldValue - why???
FROM [IssueWorklogs] AS [x]
LEFT JOIN [ContactFieldValues] AS [x.ContactFieldValue] ON [x].[ContactFieldValueId] = [x.ContactFieldValue].[Id]
LEFT JOIN [FieldValues] AS [x.ContactFieldValue.FieldValue] ON [x.ContactFieldValue].[FieldValueId] = [x.ContactFieldValue.FieldValue].[Id]
WHERE [x].[Id] IN ('e78183fb-f089-4f99-aaf3-0252679000ae', ...)
The Included are not needed in this case, they would only be useful if you projected Worklog entities themselves. If you access navigation as part of a query (in filter, projection etc) EF will automatically add all the joins it needs to perform the query.
Model classes (simplified)
And I making a query:
So, I'm selecting some fields from first (Worklog) and one from third (FieldValue) entities.
The issue
I have two problems:
I see warning in logs: The Include operation for navigation: 'x.ContactFieldValue.FieldValue' was ignored because the target navigation is not reachable in the final query results. - this is not true, because I'm selecting
Value
from it.Generated SQL
SELECT
include all columns fromContactFieldValue
and all fromFiledValue
- despite I requested only one:Further technical details
EF Core version: Microsoft.EntityFrameworkCore.SqlServer 1.1.0
Operating system: Win 8,
Framework: net461
The text was updated successfully, but these errors were encountered: