如何为 LINQ 结果表添加别名?
我正在尝试为 LINQ 结果表添加别名,但没有找到任何方法来执行此操作。
具体来说,我使用带有 CustomExpression 和 DynamicData 的 QueryExtender 来过滤 EntityDataSource。这一直有效,直到我按其中一列进行排序,此时出现错误,无法找到表“it”。 我知道这是 DynamicData 包装所有内容的表别名。
protected void FilterBasedOnDateRange(object sender, CustomExpressionEventArgs e)
{
if (filterFromDate.SelectedDate != null && filterToDate.SelectedDate != null)
e.Query = (from p in e.Query.Cast<CalendarDay>()
where p.CalendarDate >= filterFromDate.SelectedDate && p.CalendarDate <= filterToDate.SelectedDate
select p);
}
<asp:Label ID="filterFromDateLabel" runat="server" Text='From Date' Font-Bold="true" />
<telerik:RadDatePicker ID="filterFromDate" runat="server" OnSelectedDateChanged="OnSelectedDateChanged" AutoPostBack="true" >
</telerik:RadDatePicker>
<asp:Label ID="filterToDateLabel" runat="server" Text='To Date' Font-Bold="true" />
<telerik:RadDatePicker ID="filterToDate" runat="server" OnSelectedDateChanged="OnSelectedDateChanged" AutoPostBack="true" >
</telerik:RadDatePicker>
<br /><br />
<asp:QueryExtender ID="qeRange" runat="server" TargetControlID="GridDataSource">
<asp:CustomExpression OnQuerying="FilterBasedOnDateRange" />
</asp:QueryExtender>
I am trying to alias the LINQ results table, but am not finding any way to do this.
Specifally I am using QueryExtender with a CustomExpression and DynamicData to filter an EntityDataSource. This works until I sort by the one of the columns, where I get an error that table "it" cannot be found.
I know that this is the table alias that DynamicData wraps everything in.
protected void FilterBasedOnDateRange(object sender, CustomExpressionEventArgs e)
{
if (filterFromDate.SelectedDate != null && filterToDate.SelectedDate != null)
e.Query = (from p in e.Query.Cast<CalendarDay>()
where p.CalendarDate >= filterFromDate.SelectedDate && p.CalendarDate <= filterToDate.SelectedDate
select p);
}
<asp:Label ID="filterFromDateLabel" runat="server" Text='From Date' Font-Bold="true" />
<telerik:RadDatePicker ID="filterFromDate" runat="server" OnSelectedDateChanged="OnSelectedDateChanged" AutoPostBack="true" >
</telerik:RadDatePicker>
<asp:Label ID="filterToDateLabel" runat="server" Text='To Date' Font-Bold="true" />
<telerik:RadDatePicker ID="filterToDate" runat="server" OnSelectedDateChanged="OnSelectedDateChanged" AutoPostBack="true" >
</telerik:RadDatePicker>
<br /><br />
<asp:QueryExtender ID="qeRange" runat="server" TargetControlID="GridDataSource">
<asp:CustomExpression OnQuerying="FilterBasedOnDateRange" />
</asp:QueryExtender>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误是“PageRequestManagerServerErrorException:未为类型定义实例属性'it'”
我在 http://forums.asp.net/p/1528965/3696540.aspx
"在DynamicData文件夹下的List.aspx页面模板中添加实体数据源的选择事件,并添加以下几行代码在事件中。”
The error was "PageRequestManagerServerErrorException: Instance property 'it' is not defined for type "
I found the solution on http://forums.asp.net/p/1528965/3696540.aspx
"Add a selecting event for the entity data source in the List.aspx page template under DynamicData folder, and add the following lines of code in the event."