is it possible to use dynamic sorting and also serverside pageing in a linq statement?
In my Silverlight WCF-RIA application i request a data-page, for example from my customer table.
So i call my loadoperation...
public LoadOperation<VW_BP> GetPageovBP2s(BLS_DomainContext dcAct,
string sSearchText,
int iPage,
int iItemsPerPage,
string sSortOrder,
Action<LoadOperation<VW_BP>> op)
{
EntityQuery<VW_BP> loadDatas = dcAct.GetPageovBPs2Query(sSearchText, iPage, iItemsPerPage, sSortOrder);
loadDatas.IncludeTotalCount = true;
return dcAct.Load(loadDatas, LoadBehavior.MergeIntoCurrent, op, null);
}
On Serverside i have that..
public IQueryable<VW_BP> GetPageovBPs2(string sSearchText, int iPage, int iItemsPerPage, string sSortOrder, out int totalCount)
{
// Get Page of Customer-Table
totalCount = 0;
if ((sSearchText != null) &&
(sSearchText != ""))
{
totalCount = this.DataContext.ExecuteQuery<int>("select count(*) from bls.vw_bp where " +
"bls.fu_check_firma_rep('" + sCRepcode + "',bp_s_crepcode)=1 and " +
"bls.fu_check_firma_rep('" + sLRepcode + "',bp_s_lrepcode)=1 and (" +
"nvl(upper(bp_s_nr),'null') like '%" + sSearchText.ToUpper() + "%' or " +
"nvl(upper(bp_s_name),'null') like '%" + sSearchText.ToUpper() + "%' or " +
"nvl(upper(bp_s_postcode),'null') like '%" + sSearchText.ToUpper() + "%' or " +
"nvl(upper(bp_s_cityname),'null') like '%" + sSearchText.ToUpper() + "%' or " +
"nvl(upper(bp_s_host_nr),'null') like '%" + sSearchText.ToUpper() + "%' or " +
"nvl(upper(bp_s_reference),'null') like '%" + sSearchText.ToUpper() + "%') and " +
"bp_b_rcpt <> " + iRCPT.ToString() + " and bp_b_bip <> " + iBIP.ToString() + " and bp_b_db <> " + iDB.ToString() + " and bp_b_cr <> " + iCR.ToString()).FirstOrDefault();
return (from c in this.DataContext.VW_BPs
.Where(p => ((p.BP_S_NR != null && p.BP_S_NR.ToString().ToUpper().Contains(sSearchText.ToUpper()))) ||
(p.BP_S_NAME != null && p.BP_S_NAME.ToUpper().Contains(sSearchText.ToUpper())) ||
(p.BP_S_POSTCODE != null && p.BP_S_POSTCODE.ToUpper().Contains(sSearchText.ToUpper())) ||
(p.BP_S_CITYNAME != null && p.BP_S_CITYNAME.ToUpper().Contains(sSearchText.ToUpper())) ||
(p.BP_S_HOST_NR != null && p.BP_S_HOST_NR.ToUpper().Contains(sSearchText.ToUpper())) ||
(p.BP_S_REFERENCE != null && p.BP_S_REFERENCE.ToUpper().Contains(sSearchText.ToUpper())))
select c)
.OrderBy(sSortOrder)
.Skip((iPage - 1) * iItemsPerPage)
.Take(iItemsPerPage);
}
else
{
totalCount = this.DataContext.ExecuteQuery<int>("select count(*) from bls.vw_bp").FirstOrDefault();
return (from c in this.DataContext.VW_BPs
select c)
.OrderBy(sSortOrder)
.Skip((iPage - 1) * iItemsPerPage)
.Take(iItemsPerPage);
}
}
To do this i use the Dynamic.cs Class from MS which Extends the Queryable type...
When i remove the OrderBy in the Linq statement the ORM creates the correct pageing statement for the database (ORACLE).
Is there any way to have dynamic sorting and pageing correctly sent to the DB?
Glad for any ideas or solutions...
regards Richard.