English 中文(简体)
如何将由INNER JOIN、LEFT JOIN和小组组成的质子转换为类似的林克2sql格格格格?
原标题:How to convert a query consisting of INNER JOIN, LEFT JOIN and GROUP BY to a similar linq2sql query?

I m试图将以下T-SQL问题转换为linq2sql。 无论我做什么,它还是把它转化为一些新生事物,并加入其中。 任何建议?

表A、B、C

SELECT A.Id, A.Name, Pool.Total
FROM A
INNER JOIN B ON A.Id = B.AId
LEFT JOIN (
SELECT AId,
SUM(Quantity) as Total
FROM C 
GROUP BY AId) AS Pool ON A.Id = C.AId
WHERE Pool.Total < B.Threshold
问题回答

我写了一份准则调查表,它的确向佩雷斯翻译,但execution plan看上去,批次中的查询费用为50/50,因此,翻译的询问是相同的(或是同义词)。

The linq query is

from a in As 
join b in Bs on a.ID equals b.AID 
join  pool in (from c in Cs
                group c by c.AId into cG
                select new {AID = cG.Key,Total = cG.Sum(c=>c.Quantity)} ) on a.ID equals pool.AID into poolG
from pool in poolG.DefaultIfEmpty()
where pool.Total<b.Threshold 
select new {a.ID, a.Name, pool.Total}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签