这里是我的SQL查询SQL中工作正常:任何人都可以帮助我将SQL转换为linq查询。我尝试,但未能
select ld.FolderId, count(ld.LeadId) LeadID, sum(note.noteCount) NoteCount, count(ld.CallResultId) Calls
from LeadsDetails ld
left join
(
select lnh.LeadId, Count(lnh.NoteId) as noteCount
from [dbo].[LeadNoteHistory] lnh
group by lnh.LeadId
)note
on note.LeadId=ld.LeadId
group by ld.FolderId
我试过 -
var query =
from lead in _context.LeadsDetails
join note in _context.LeadNoteHistories
on lead.LeadId equals note.LeadId into g
from notes in g.DefaultIfEmpty()
group lead by lead.FolderId into grp
select new
{
FolderId = g.FolderId,
LeadID = g.LeadId,
NoteCount = notes.NoteId,
Call = lead.CallResultId
};
不能得到正确的结果。请告诉我做错了什么。
你之后的结果是什么? – SandPiper
请参阅sql查询。我想创建精确查询LINQ – James
http://www.sqltolinq.com/ –