2013-04-02 73 views
0

我有一個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(); 

回答

0

如果我undertand你的權利,你可以用這樣的方式:

<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

+0

這是什麼都與我的問題呢? – Dineshp

+0

正如我告訴過的,如果我對你的問題有所瞭解,你可以OrderBy爲你的EntityDataSource添加一個屬性。你說過你使用Linq,但是想在EntityDataSource中做,對嗎? –