linq - how to sort a list
- by Billy Logan
Hello everyone,
I have a linq query that populates a list of designers. since i am using the filters below my sorting is not functioning properly.
My question is with the given code below how can i best sort this List after the fact or sort while querying?
I have tried to sort the list after the fact using the following script but i receive a compiler error:
List<TBLDESIGNER> designers = new List<TBLDESIGNER>();
designers = 'calls my procedure below and comes back with an unsorted list of designers'
designers.Sort((x, y) => string.Compare(x.FIRST_NAME, y.LAST_NAME));
Query goes as follows:
List<TBLDESIGNER> designer = null;
using (SOAE strikeOffContext = new SOAE())
{
//Invoke the query
designer = AdminDelegates.selectDesignerDesigns.Invoke(strikeOffContext).ByActive(active).ByAdmin(admin).ToList();
}
Delegate:
public static Func<SOAE, IQueryable<TBLDESIGNER>> selectDesignerDesigns =
CompiledQuery.Compile<SOAE, IQueryable<TBLDESIGNER>>(
(designer) => from c in designer.TBLDESIGNER.Include("TBLDESIGN")
orderby c.FIRST_NAME ascending
select c);
Filter ByActive:
public static IQueryable<TBLDESIGNER> ByActive(this IQueryable<TBLDESIGNER> qry, bool active)
{
//Return the filtered IQueryable object
return from c in qry
where c.ACTIVE == active
select c;
}
Filter ByAdmin:
public static IQueryable<TBLDESIGNER> ByAdmin(this IQueryable<TBLDESIGNER> qry, bool admin)
{
//Return the filtered IQueryable object
return from c in qry
where c.SITE_ADMIN == admin
select c;
}
Thanks in advance,
Billy