I've written compiled queries for my ObjectContext which I use as select methods in a ObjectDataSource. The proble is that I now want to implement sorting and paging and I'd like to it in data layer which means I need to add .OrderBy and .Take/.Skip to my compiled queries. Does this make sense? I mean won't the compiled query recompile every time any parameter changes? Should go back to regular Linq to Entities queries? It should be something like this:
namespace BLL
{
[DataObject(true)]
public class CompanyManager
{
private static readonly Func<DBContext, IEnumerable<CompanyInfo>> companyList;
static CompanyManager()
{
if (companyList== null)
{
companyList= CompiledQuery.Compile<DBContext, IEnumerable<CompanyInfo>>(
(DBContext vt) =>
from row in vt.Companies
select new CompanyInfo()
{
...
}
);
}
}
[DataObjectMethod(DataObjectMethodType.Select)]
public static List<CompanyInfo> CompanyList()
{
List<CompanyInfo> list= new List<CompanyInfo>();
using (var vt = DBContext.Instance())
{
//ORDERBY AND THE REST WILL BE ADDED
list.AddRange(companyList(vt)).OrderBy(row => row.CompanyName).Skip(20).Take(10);
}
return list;
}
}
}
ads