Selecting top(n) 2 Related Tables Entity Framework
本文关键字:Related Tables Entity Framework top Selecting | 更新日期: 2023-09-27 17:59:46
这是我的实体数据源
<asp:EntityDataSource ID="EntityDataSourceCLient" runat="server"
ConnectionString="name=MBSDbEntities" DefaultContainerName="MBSDbEntities"
EnableFlattening="False" EntitySetName="ReservationLists" Include="UserProfile" OrderBy="it.Date" Where="">
</asp:EntityDataSource>
这是我的网格视图
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="ID" DataSourceID="EntityDataSourceCLient">
<Columns>
<asp:TemplateField HeaderText="UserID" SortExpression="UserProfile.FirstMidname">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("UserProfile.FirstMidname") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("UserProfile.FirstMidname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TransactionType" HeaderText="TransactionType"
SortExpression="TransactionType" />
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
我可以显示2个相关表格,但我不能显示具体的数量。你们能帮我吗?提前谢谢。
您需要加入表,然后根据字段(可能是TestDate)对它们进行排序,然后使用Enumerable.Take()获取顶级5
记录。类似的东西
var query = (from q in table1
join r in table2 on q.UserID equals r.UserID)
.OrderBy(s=> s.TestDate)
.Take(5);