如何在EntityDataSource中添加子表的计数

发布于 2024-11-27 08:11:31 字数 1262 浏览 1 评论 0原文

我有一个 EntityDataSource,用于从 tblOrderFile 获取行数据,如下所示:

<asp:EntityDataSource ID="entityDataSourcePreorder" runat="server" 
        ConnectionString="name=iDBEntities" 
        DefaultContainerName="iDBEntities" EnableFlattening="False" 
        EntitySetName="tblOrderFiles" 
        Select="it.[pkOrderFileID], it.[fkOrderFileStatusID], it.[Filename], it.[CreateDate], it.[UserId]" 
        AutoGenerateWhereClause="True" EntityTypeFilter="" Where="">

我现在想修改它以返回子表 tblOrderFileItem 中的行数(实体集名称为 tblOrderFileItems)。

我找到了一种通过添加 Include 指令来使计数工作的方法,如下所示:

    <asp:EntityDataSource ID="entityDataSourcePreorder" runat="server" 
        ConnectionString="name=iDBEntities" 
        DefaultContainerName="iDBEntities" EnableFlattening="False" 
        EntitySetName="tblOrderFiles" Include="tblOrderFileItems"
        AutoGenerateWhereClause="True" EntityTypeFilter="" Where="" >
    </asp:EntityDataSource>

但我相信这会返回每个订单项的所有行的所有列。我只想要计数,不想将其余数据传递到网页。

我也尝试简单地将 it.tblOrderFileItems.Count 添加到 Select 语句中,但收到错误消息

“Count”不是“Transient.collection[MyDBModel.tblOrderFileItem(Nullable=True,DefaultValue=)]”的成员。要提取集合元素的属性,请使用子查询来迭代集合。

I have an EntityDataSource that works to get row data from tblOrderFile as follows:

<asp:EntityDataSource ID="entityDataSourcePreorder" runat="server" 
        ConnectionString="name=iDBEntities" 
        DefaultContainerName="iDBEntities" EnableFlattening="False" 
        EntitySetName="tblOrderFiles" 
        Select="it.[pkOrderFileID], it.[fkOrderFileStatusID], it.[Filename], it.[CreateDate], it.[UserId]" 
        AutoGenerateWhereClause="True" EntityTypeFilter="" Where="">

I would now like to modify it to also return back the number of rows in child table tblOrderFileItem (with Entity Set Name tblOrderFileItems).

I found a way to get the Count to work by adding an Include directive as follows:

    <asp:EntityDataSource ID="entityDataSourcePreorder" runat="server" 
        ConnectionString="name=iDBEntities" 
        DefaultContainerName="iDBEntities" EnableFlattening="False" 
        EntitySetName="tblOrderFiles" Include="tblOrderFileItems"
        AutoGenerateWhereClause="True" EntityTypeFilter="" Where="" >
    </asp:EntityDataSource>

but I believe this is returning the all the columns of all the rows for each Order Item. I only really want the Count and do not want to deliver the rest of the data to the web page.

I also tried simply adding it.tblOrderFileItems.Count to the Select statement but get an error saying

'Count' is not a member of 'Transient.collection[MyDBModel.tblOrderFileItem(Nullable=True,DefaultValue=)]'. To extract a property of a collection element, use a subquery to iterate over the collection.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

明媚殇 2024-12-04 08:11:31
Select="ANYELEMENT(SELECT VALUE Count(c.ItemId) FROM it.tblOrderFileItems AS c) as ChildCount"
Select="ANYELEMENT(SELECT VALUE Count(c.ItemId) FROM it.tblOrderFileItems AS c) as ChildCount"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文