C# 将postgres sql转换为linq。可能吗?
我需要将下一个sql翻译成linq,有可能吗?速度大致相同C# 将postgres sql转换为linq。可能吗?,c#,sql,linq,postgresql,C#,Sql,Linq,Postgresql,我需要将下一个sql翻译成linq,有可能吗?速度大致相同 SELECT Count(tblcollectionimage.lngimageid), tblcollectiontree.lngcollectionid, tblcollection.txtname FROM (tblcollectiontree LEFT JOIN tblcollectionimage ON blcollectiontree.
SELECT Count(tblcollectionimage.lngimageid),
tblcollectiontree.lngcollectionid,
tblcollection.txtname
FROM (tblcollectiontree
LEFT JOIN tblcollectionimage
ON blcollectiontree.lngcollectionid =
tblcollectionimage.lngcollectionid)
JOIN tblcollection
ON tblcollectiontree.lngcollectionid = tblcollection.lngcollectionid
WHERE lngcollectionparentid = 0
GROUP BY tblcollectiontree.lngcollectionid,
tblcollection.txtname
我目前有这样的linq,但它不工作
var results =(from collection in dataBase.tblcollections
join collectionTree in dataBase.tblcollectiontrees on
collection.lngcollectionid equals collectionTree.lngcollectionid
into generalCollections
from generalCollection in generalCollections
join images in dataBase.tblcollectionimages on
collection.lngcollectionid equals images.lngcollectionid
into generalCollectionImages
from generalCollectionImage in
generalCollectionImages.DefaultIfEmpty()
group generalCollectionImage by
generalCollectionImage.lngcollectionid into hello
from hellos in hello.DefaultIfEmpty()
join collection in dataBase.tblcollections on
hello.Key equals collection.lngcollectionid
select new
{
id = hello.Key,
name = hello.Count()
}).ToList();
欢迎来到堆栈溢出!如果你还没有,请看看这些技巧,以改进你的问题,并得到更好的答案:和。另外,请格式化您的代码,使其尽可能可读。您可能希望从我收集的信息中了解实体框架。我自己不使用.NET。