EntityDataSource supports multiple relationship bindings.

.net asp.net entity-framework entity-relationship

Question

For my database, I have an ADO.Net Entity Data Model. I have three connected tables in this model: "Users" table with UserId and other information. RunId, ApproverId, and other information are included in the "Run" Table. "RunToUser," which has columns for UserId and RunId

These are the relationships: Users. Run and UserId have a one to one connection. ApproverId\sUser. RunToUser and UserId are many to many. UserId\sRun. RunToUser and RunId are many to many. RunId

This is represented by two tables and two distinct relationships in the entity model. Users and Run have both a one-to-one and a many-to-many connection with one another.

I want to change the data in Run and the associated data in Users in an ASP.net Formview.

In most situations, databinding is effective. However, it always uses the one-to-one connection association when I attach to the Users table as an entitydatasource.

In order to link the information from the one-to-one mapping to a label and the many-to-many mapping to a dataview, how can I compel the entitydatasource to utilize a certain relationship association?

Although I tried adding the "EXISTS" in the where clause to restrict the records, it insisted on always utilizing the one-to-one relationship and only displaying the one user in all databound controls. The entitydatasource for users is as follows:

  <asp:EntityDataSource ID="edsUsers_DET" runat="server" 
        ConnectionString="name=MyEntities" DefaultContainerName="MyEntities" 
        EntitySetName="Users" 
        Where="EXISTS(SELECT VALUE p FROM it.Run AS p WHERE p.RunID = @RunID)" >
        <WhereParameters>
           <asp:ControlParameter ControlID="fvRun"  Name="RunID" Type="Int32" />
        </WhereParameters>        
    </asp:EntityDataSource>

I suppose I'll need two entity data sources—one for the label and another for the gridview—but I have no idea how to go on until I figure out how to specify an association. Thx, -J

1
0
7/1/2009 7:50:00 PM

Accepted Answer

Just checking in because I already had the solution and neglected to close the question.

I learned that connections with the same foreign table that have many members automatically get a number suffix. Thus, Users and Users1 were associated in the Run table. You would need to know which association to utilize when using the "Include" Parameter for the EDS, which isn't clear unless you check at the EDS model.

I went through and gave new names to every association I had that had a number. Instead of Users1, my Run table now has a relationship with Users and an Approver. This makes it simple for me to determine which relations to ship for both the LINQ and the EDS declarative sections.

I would go as follows if I wanted to add both associations for the EDS:

Include="Users,Approver"

Since it wasn't immediately clear to me, I hope this helps someone else as well.

3
8/14/2009 8:29:00 PM

Popular Answer

If your database has a one-to-one connection, you may construct your entity model such that these two tables look as a single table.

Your bond gets considerably easier if you construct it in this manner.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow