2014-12-05 80 views
1

有兩個表誰能幫我使用LINQ排序

FeatureComparision

FKFeatureId FKHandsetId Value 
29   208  207MP 
46   208  upto 11h 

功能

PKFeatureId FeatureName DisplayInOverview SortOrder 
29   Focus  1       1 
46   StandBy  1       2 
//DisplayInOverview column is of type bit 

與SQL所需的輸出是

select f.featurename,fc.Value 
from FeatureComparision fc 
join Feature f on fc.FKFeatureId = f.PKFeatureId 
Where fc.FKHandSetId = 208 and f.DisplayInOverview=1 
order by f.SortOrder 

和LINQ是

var Specs = from fc in objCache.LstFeatureComparisions 
      join f in objCache.LstFeatures 
      on fc.FKFeatureId equals f.PKFeatureId 
      where (fc.FKHandSetId == 208 && f.DisplayInOverview == true) 
      select new 
      { 
      f.FeatureName, 
      fc.Value 
      }; 

我該怎麼辦的有點像SQL在此LINQ

+0

我看不出有什麼不妥。你確定你指向同一個數據庫嗎? – thepirat000 2014-12-05 05:49:54

+1

您是否嘗試過檢查「DisplayInOverview == 1」?有一點不是布爾值,除非像這樣。 – Eris 2014-12-05 05:52:17

+0

這不是左連接 – thepirat000 2014-12-05 05:55:14

回答

2

添加orderby字符串:

var Specs = from fc in objCache.LstFeatureComparisions 
     join f in objCache.LstFeatures 
     on fc.FKFeatureId equals f.PKFeatureId 
     where (fc.FKHandSetId == 208 && f.DisplayInOverview) 
     orderby f.SortOrder ascending 
     select new 
     { 
     f.FeatureName, 
     fc.Value 
     };