Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Datarelation questions...
Message
From
17/07/2003 01:56:46
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
16/07/2003 17:50:32
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00810871
Message ID:
00810961
Views:
11
>If 2 tables are related using the dataRelation object,
>do deletes cascade through the established in memory relationship?
>
>Can you related more that 2 tables using a single DataRelation Object?
>will the code below work?
>
>
> DataColumn Tables;
> DataColumn Chairs;
> DataColumn TablesToChairs;
> // Code to get the DataSet not shown here.
> Tables = DataSet1.Tables["Tables"].Columns["TableID"];
> TablesToChairs = DataSet1.Tables["TableToChairRel"].Columns["TableID"];
> Chairs = DataSet1.Tables["Chairs"].Columns["ChairID"];
> // Create DataRelation.
> DataRelation relTablesToChairs;
> relTablesToChairs = new DataRelation("CustomersOrders", Tables, TableToChair,Chairs);
> // Add the relation to the DataSet.
> DataSet1.Relations.Add(relTablesToChairs);
>
>Thanks for your help,
>
>Alvin

Alvin,

Cascading updates and deletes are handled by a separate class, called ForeignKeyConstraint. For deletes, you have the option of deleting the child rows, setting the Foreign Key to Null or setting it to the default value.

When you create a DataRelation, a corresponding ForeignKeyConstraint is also created by default. It can be referenced with relTablesToChairs.ChildKeyConstraint.

You cannot relate more than two tables with a single DataRelation. You would have to create two DataRelation objects. One that relates "Tables" to "TableToChairRel" and another one that relates "Chairs" to "TableToChairRel".

When you use a third table to create a many-to-many relationship, it implies that "Tables" and "Chairs" do not have a strict parent/child structure. I.e. "Tables" can have many "Chairs" and "Chairs" can belong to many "Tables". Therefore, you would not want to cascade the delete from the "Tables" all the way to the "Chairs".

Because of the names of the entities you have chosen, I suspect that you may be confused about the temporal nature of the relationship. A "Chair" can belong to only one table at a given time, but may be "moved" to a different "Table" in the future. In this case, the "Chairs" entity should be a child of the "Tables" entity. When a chair is moved to a different table, simply update the TableID foreign key in the "Chairs" entity.

For example, if you are remodeling the dining room and a "Table" is discarded, set the TableID in the "Chairs" entity to Null or a default value, but do not cascade the delete unless you intend to discard the "Chairs" with the "Table".

Good Luck!
Previous
Reply
Map
View

Click here to load this message in the networking platform