Multiple Parents

  • Thread starter Thread starter Blake Weaver
  • Start date Start date
B

Blake Weaver

Ok, I've already figured out that its not allowed to have 2 (or more)
parents to 1 child table in .NET. (unless I'm totally misinformed).
http://support.microsoft.com/default.aspx?scid=kb;en-us;325695

So, how do you get around it. Surely there are plenty of you who have run
into this. In my case I have 3 tables (more actually but 3 will suffice for
now): PurchaseOrders, Tickets, and Items. Should be a pretty classic
example.

A customer walks into the shop and places an order for various items which
come from several different vendors, therefore these items will belong to
several different PurchaseOrders. A Ticket is created for the customer,
listing all the items. Thus, a Tickets to Items relationship is implied.
However, at the end of the day (or end of the week, etc) the purchaser draws
up a series of PurchaseOrders. The PurchaseOrder will have all the items
from a particular vendor, for all the Tickets that were generated that day
(or week, etc). So, the PurchaseOrder Table needs a relationship with Items
as well. Thus, 2 parents, same child.

How does ADO.NET handle this? How do I handle this?

Thanks,
Blake
 
Hi Blake,

Blake Weaver said:
Ok, I've already figured out that its not allowed to have 2 (or more)
parents to 1 child table in .NET. (unless I'm totally misinformed).
http://support.microsoft.com/default.aspx?scid=kb;en-us;325695

Why not? It is perfectlly leagal to have more then one parent.
So, how do you get around it. Surely there are plenty of you who have run
into this. In my case I have 3 tables (more actually but 3 will suffice for
now): PurchaseOrders, Tickets, and Items. Should be a pretty classic
example.

A customer walks into the shop and places an order for various items which
come from several different vendors, therefore these items will belong to
several different PurchaseOrders. A Ticket is created for the customer,
listing all the items. Thus, a Tickets to Items relationship is implied.
However, at the end of the day (or end of the week, etc) the purchaser draws
up a series of PurchaseOrders. The PurchaseOrder will have all the items
from a particular vendor, for all the Tickets that were generated that day
(or week, etc). So, the PurchaseOrder Table needs a relationship with Items
as well. Thus, 2 parents, same child.

How does ADO.NET handle this? How do I handle this?

Create three tables, and relations between them :)
 
Miha,
Thanks for the reply, but you may be oversimplifying things... or, again, I
might be reading this all wrong. First thing, that knowledge base article I
pointed to (
http://support.microsoft.com/default.aspx?scid=kb;en-us;325695 ), says you
can't do two parents... is it wrong? And secondly, I did try to put the 3
tables in a dataset and add the relations. That part works fine. But when I
tried to .Fill them, I had constraint violations. I've checked to ensure the
data in the tables meet the constraints so I assumed it was a problem with
having two parents.

This is the error I caught: "System.Data.ConstraintException: Failed to
enable constraints. One or more rows contain values violating non-null,
unique, or foreign-key constraints."

Thanks again for any insight,
Blake
 
Update:
I did manage to get the Fills to work. I had a Primary Key set in each
table. PO_ID, TicketID, ItemID respectively. I had a relation from TicketID
to ItemID that worked fine and a relation from PO_ID to ItemID that worked
fine until I called Fill. I had these Primary Keys set in the DataSet as
well as the real underlying SQL tables. When I deleted the PK from the PO_ID
in the SQL table, (still had it in the DataSet), the .FIll worked fine.
Whats the deal?

Thanks,
Blake
 
Hi Blake,

Blake Weaver said:
Miha,
Thanks for the reply, but you may be oversimplifying things...

:) no, it is simple actually.

or, again, I
might be reading this all wrong. First thing, that knowledge base article I
pointed to (
http://support.microsoft.com/default.aspx?scid=kb;en-us;325695 ), says you
can't do two parents... is it wrong? And secondly, I did try to put the 3
tables in a dataset and add the relations. That part works fine. But when I
tried to .Fill them, I had constraint violations. I've checked to ensure the
data in the tables meet the constraints so I assumed it was a problem with
having two parents.

This is the error I caught: "System.Data.ConstraintException: Failed to
enable constraints. One or more rows contain values violating non-null,
unique, or foreign-key constraints."

Yes, sure. You have two ways to deal with it:
1. Fill tables in right order (first parents, then child)
2. Before Fill, set EnforceConstraints = false, do the fill and
re-enforceconstraints at the end of the operation.
 
Back
Top