实体数据源过滤器

时间:2013-04-02 14:43:00

标签: asp.net c#-4.0 entitydatasource

我有entity datasource,我想过滤它(created_on)以仅显示最大日期。我该怎么做呢?

<asp:EntityDataSource ID="Payroll_DetailsDS" runat="server" 
                ConnectionString="name=sspEntities" DefaultContainerName="sspEntities" 
                EnableDelete="True" EnableFlattening="False" EnableInsert="True" 
                EnableUpdate="True" EntitySetName="Payroll_Details" 
                OrderBy="it.[Payslip_no] desc" EntityTypeFilter="" Select="" 
                Where="it.Status = &quot;COM&quot;">
 </asp:EntityDataSource>

现在,数据源仅通过it.status进行过滤。我也想通过it.created_on = Max(created_On)过滤..这就是我想要的想法,不知道如何得到它。

我能够在linq得到类似的东西,但它运行良好。只需要entity datasource

var testquery = from d in context.Payroll_Details
                                        where d.Created_on == ((from b in                                      context.Payroll_Details
                                        where b.Employee_Personal_InfoEmp_id == xyz.PD_EmpPersonal_Id
                                        select b.Created_on).Max())
                                        select new
                                        {
                                            d.Employee_Personal_InfoEmp_id,
                                            d.Basic_Pay_YTD
                                        };
                        var r = testquery.SingleOrDefault();

1 个答案:

答案 0 :(得分:0)

如果我理解你,你可以这样使用:

<asp:EntityDataSource ID="SalesOrderHeader" runat="server" 
  ConnectionString="name=AdventureWorksEntities" 
  DefaultContainerName="AdventureWorksEntities" EnableDelete="True" 
  EnableInsert="True" EnableUpdate="True" EntitySetName="SalesOrderHeader" 
  EntityTypeFilter="" OrderBy="it.TotalDue DESC" Select="" 
   Where="it.OnlineOrderFlag = TRUE AND it.TotalDue &gt; @ordercost">
  <WhereParameters>
    <asp:ControlParameter ControlID="costLimit" DbType="Int32" 
      DefaultValue="2500" Name="ordercost" PropertyName="Text" />
  </WhereParameters>
</asp:EntityDataSource>

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.entitydatasource.orderby.aspx