locked
entitydatasource.... master details... querying RRS feed

  • Question

  • I want to do what I would think is a simple task but I am having a hard time with this using the entitydatasource.....

    I have two tables in my entity model with a one to many relationship...

    I need two datasources in my app....

    the first I would pull from my blog entry table(1) this is my master form...

    I then want to pull all the records associated with the master's ID from a second table(many)


    How do I query for this?  This seems like a simple task but yet I am having trouble finding any information on this...

    I know about controlparameters but in my case it doesn't seem to work...

    <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
    ConnectionString="name=travlan_Teaching_BlogEntities"
    DefaultContainerName="travlan_Teaching_BlogEntities"
    EntitySetName="Blog_Entries"
    Select="it.[ID], it.[Series], it.[Unit], it.[Start_Date], it.[End_Date], it.[Post_Date], it.[Additional_Comments]"
    orderby="it.[Post_Date] DESC">
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="EntityDataSource_ReadingB" runat="server"
    ConnectionString="name=travlan_Teaching_BlogEntities"
    DefaultContainerName="travlan_Teaching_BlogEntities" EntitySetName="Links"
    Select="it.[Class_Level], it.[Class_Type], it.[Link_Type], it.[Title], it.[Description], it.[URL], it.[Picture_Thumb_Location], it.[Picture_Location], it.[Picture_Alt], it.[Article_Number], it.[Article_Title]"
    AutoGenerateWhereClause="true">
    <WhereParameters>
    <asp:ControlParameter ControlID="FormView1" Name="Blog_Entries.ID" />
    </WhereParameters>
    </asp:EntityDataSource>
    for the master form I just pull all blogentries but if I try to use the ControlParameter and pull the details associated to these entries I get all the details.  In other words the details are not being filtered....

    I've tried alot of solutions... what boggles me is that I can't reference my foreign key(entitydatasource_ReadingB) in my select statement...
    Monday, July 27, 2009 2:30 AM

Answers

  • Hello,

    When you use AutoGenerateWhereClause in the EntityDataSource, the Name property in each of the WhereParameters has to match a property name in the entity or the projection. Names that represent paths of properties (such as Blog_Entries.ID" in your example) are not recognized. You can find about this in the online documentation of the EntityDataSource.

    This scenario is quite easy to implement, but you have to turn automatic generation of the where clause off (i.e. set it to AutoGenerateWhereClause="false") and set a WHERE clause in the EntityDataSouce (i.e. Where = "it.Blog_Entries.ID = @Blog_Entry_ID"), then the parameter name in the WhereParameters collection has to match the name of the "@" parameter used in the WHERE clause (i.e. Name ="Blog_Entry_ID").

    Hope this helps,
    Diego


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, July 27, 2009 4:41 AM