将postgres sql翻译成linq。可能吗?

时间:2014-04-10 07:55:13

标签: c# sql linq postgresql

我需要翻译下一个sql到linq是否有可能?那将具有大致相同的速度

  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();

0 个答案:

没有答案