sukesh
sukesh

Reputation: 2423

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

Upvotes: 1

Views: 67

Answers (1)

Vlad
Vlad

Reputation: 1439

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

Upvotes: 2

Related Questions