开发者

How to add Count of child table in EntityDataSource

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 simpl开发者_StackOverflow社区y 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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜