如何为 LINQ 结果表添加别名?

发布于 2024-10-21 05:12:31 字数 1364 浏览 1 评论 0原文

我正在尝试为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懵少女 2024-10-28 05:12:31

错误是“PageRequestManagerServerErrorException:未为类型定义实例属性'it'”

我在 http://forums.asp.net/p/1528965/3696540.aspx

"在DynamicData文件夹下的List.aspx页面模板中添加实体数据源的选择事件,并添加以下几行代码在事件中。”

string s=e.SelectArguments.SortExpression; 
if(s.StartsWith("it.")) 
  e.SelectArguments.SortExpression = s.Substring(3);

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."

string s=e.SelectArguments.SortExpression; 
if(s.StartsWith("it.")) 
  e.SelectArguments.SortExpression = s.Substring(3);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文