這裏是我的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/ –