2011-10-05 169 views
1

任何人都可以告訴我,如何在LINQ中編寫此查詢?LINQ to Entities中的SQL查詢

select a.UTP_NAME, b.UPS_NAME, c.USS_NAME from 
    TB_UTILIDADE_PUBLIC_UTP a inner join 
    TB_UTILIDADE_PUBLIC_SECTOR_UPS b on 
    a.UPS_ID = b.UPS_ID 
     inner join TB_UTILIDADE_PUBLIC_SUBSECTOR_USS c 
on a.USS_ID = c.USS_ID and a.UPS_ID = c.UPS_ID /* IMPORTANT LINE! */ 

謝謝。

回答

2

創建一個新的匿名類型,您可以使用多個標準

var query = from a in context.TB_UTILIDADE_PUBLIC_UTP 
      join b in context.TB_UTILIDADE_PUBLIC_SECTOR_UPS 
       on a.UPS_ID equals b.UPS_ID 
      join c in context.TB_UTILIDADE_PUBLIC_SUBSECTOR_USS 
       on new { a.USS_ID, a.UPS_ID } equals new { c.USS_ID, c.UPS_ID } 
      select new 
      { 
       a.UTP_NAME, 
       b.UPS_NAME, 
       c.USS_NAME 
      }; 
+0

不錯!謝謝你的加入。 – ozsenegal