【发布时间】:2012-03-01 17:31:15
【问题描述】:
我正在尝试使用我的 objectdatasource 对 gridview 进行排序,该 objectdatasource 使用来自我的实体模型的函数导入(存储过程)。我遵循的指南来自 http://www.asp.net/web-forms/tutorials/continuing-with-ef/using-the-entity-framework-and-the-objectdatasource-control-part-3-sorting-and-filtering
哪个有这个代码:
public IEnumerable<Department> GetDepartments(string sortExpression)
{
if (String.IsNullOrWhiteSpace(sortExpression))
{
sortExpression = "Name";
}
return context.Departments.Include("Person").OrderBy("it." + sortExpression).ToList();
}
如果我正在调用存储过程,我该如何执行 OrderBy?
我的代码:
If String.IsNullOrWhiteSpace(sortExpression) Then
sortExpression = "Status"
End If
retReq = dataContext.usp_GetReport(Nothing, Nothing, Nothing, period, Nothing, Nothing, _
Nothing, Nothing, Nothing).ToList()
有什么想法吗?提前致谢
更新 - 解决方案
我确信有一种更好的方法可以让排序功能在我的情况下发挥作用。但这是我所做的方法,它有效,但如果有人可以帮助我简化它,请告诉我谢谢。
源自msdn的文档http://msdn.microsoft.com/en-us/library/bb534966(v=vs.96).aspx#Y1200
If sortExpression IsNot Nothing Then
If sortExpression = "StatusDate DESC" Then
retReq = dataContext.usp_GetReport(Nothing, Nothing, Nothing, period, Nothing, Nothing, _
Nothing, Nothing, Nothing).OrderByDescending(Function(test As usp_GetReport_Result) test.StatusDate).ToList()
ElseIf sortExpression = "StatusDate" Then
retReq = dataContext.usp_GetReport(Nothing, Nothing, Nothing, period, Nothing, Nothing, _
Nothing, Nothing, Nothing).OrderBy(Function(test As usp_GetReport_Result) test.StatusDate).ToList()
End If
End If
【问题讨论】:
标签: function gridview frameworks import entity