简体   繁体   中英

Can anyone help me with Linq Sorting

There are two tables

FeatureComparision

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

Feature

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

Desired output with sql is

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

and the linq is

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
            };

How can I do the sort like sql in this linq

Add orderby string:

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
        };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM