如何在EntityDataSource中添加子表的计数 [英] How to add Count of child table in EntityDataSource
问题描述
我有一个EntityDataSource,用于从tblOrderFile获取行数据,如下所示:
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="">
我现在想修改它也返回子表中的行数tblOrderFileItem实体集名称tblOrderFileItems)。
I would now like to modify it to also return back the number of rows in child table tblOrderFileItem (with Entity Set Name tblOrderFileItems).
我发现通过添加一个Include指令来使Count工作的方法如下:
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>
但我相信这是返回每个订单项的所有行的所有列。我只是真的想要Count,不想将其余的数据传递到网页。
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.
我也试过简单地添加it.tblOrderFileItems.Count到Select语句,但得到错误说
I also tried simply adding it.tblOrderFileItems.Count to the Select statement but get an error saying
'Count'不是'Transient.collection [MyDBModel.tblOrderFileItem(Nullable = True,DefaultValue =)]'。要提取集合元素的属性,请使用子查询对集合进行迭代。
'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.
推荐答案
Select="ANYELEMENT(SELECT VALUE Count(c.ItemId) FROM it.tblOrderFileItems AS c) as ChildCount"
这篇关于如何在EntityDataSource中添加子表的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!