Я написал это левое соединение в LINQ, и я выбрал только PersonId
из SHPerson
таблицы, но в SQL Server Profiler я получил PersonId
из SHPFA
таблицы.
var spfQuery = from n in shHPFARepository.GetAll()
.AsNoTracking()
.Where(t => t.ShareCount > 0)
group n by new { n.PersonId } into nGroup
select new
{
nGroup.Key.PersonId,
TotalhareCount = nGroup.Sum(t => t.ShareCount)
};
var query = (from sp in SHPersonRepository.GetAll().AsNoTracking()
join spf in spfQuery on sp.Id equals spf.PersonId
select new SHPOutputDto
{
PersonId = sp.PersonId,
ShareCount = spf.TotalShareCount,
IsShareHolder=true
});
var resultDto = await query.ToListAsync();
Я не хочу, чтобы SHPFA.PersonId
([t0]. [PersonId]) выбирался в запросе.
SELECT [t0].[PersonId], [t0].[TotalShareCount], [e].[PersonId]
FROM [SHolders].[SHPerson] AS [e]
INNER JOIN
(SELECT [t].[SHPersonId], SUM([t].[ShareCount]) AS [TotalShareCount]
FROM [SHolders].[SHPFA] AS [t]
WHERE [t].[ShareCount] > 0
GROUP BY [t].[PersonId]) AS [t0] ON [e].[Id] = [t0].[PersonId]