任何人都可以帮我Linq排序

时间:2014-12-05 05:47:45

标签: c# 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
            };

如何在此linq

中进行类似sql的排序

1 个答案:

答案 0 :(得分: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
        };