Description
Only one column from second table is specified for join, but when query is analysed from SqlProfiler it selects all columns.
Steps to reproduce
Main Table
User
Guid UserId (PK)
string Email
string FullName
Guid? PartyId (FK nullable)
Join Table
Party
Guid PartyId (PK)
string Name
string Desc
string SomeInfo
Linq:
var users = userRepos.Query().Where(a => !a.Deleted).OrderBy(u => u.UserId).Skip(0).Take(10);
var query = from u in users
select new UserModel
{
UserId = = u.UserId,
Email = u.Email,
FullName = u.FullName,
PartyId = u.PartyId,
PartyName = u.Party.Name,
};
Profiler:
SELECT [dto.Party].[PartyId], [dto.Party].[Name], [dto.Party].[Desc], [dto.Party].[SomeInfo],
[t].[UserId], [t].[FullName], [t].[Email], [t].[PartyId]
FROM (
SELECT [u0].*
FROM [dbo].[User] AS [u0]
WHERE [u0].[Deleted] = 0
ORDER BY [u0].[UserId]
OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY
) AS [t]
LEFT JOIN [fin].[Party] AS [dto.Party] ON [t].[PartyId] = [dto.Party].[PartyId]
ORDER BY [t].[PartyId]
Columns Desc and SomeInfo should NOT be in query.
This showcase was simplified just to emphasis the issues.
In real scenario Party table has much more columns and some tables have more then one nullable FK, so I don't want all those column loaded from DB when I do not need them.
I am actually using AutoMapper instead of manually mapping these Properties but generated query is same in both cases. Showcase is with manual mapping just to point that it's not because of AM.
Further technical details
EF Core version: 1.1.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017