How to add Count of child table in EntityDataSource

纵饮孤独 提交于 2019-12-11 13:42:01

问题


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.


回答1:


Select="ANYELEMENT(SELECT VALUE Count(c.ItemId) FROM it.tblOrderFileItems AS c) as ChildCount"


来源:https://stackoverflow.com/questions/6917481/how-to-add-count-of-child-table-in-entitydatasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!