M
Michael Lang
Ok, I've looked into using ints as primary key fields in my 3 layered
application. I've been able to get single tables to update correctly, and
have the database assigned key assigned to each DataRow. This is fine and
good for tables that don't have child records in other tables.
What do you do if in this situation:
table : "Order" with columns:
OrderID (int PK)
CustomerID (int FK)
Descriptor (nNarChar)
table: "OrderDetails" with columns:
OrderDetailsID (int PK)
OrderID (int FK)
ProductID (int FK)
Quantity (int)
also tables "Product" and "Customer" with PK's matching FK's above.
The business layer has been populated by querying the datalayer. In the
presentation layer the user adds 5 new customers (sales had a good day ,
10 new orders for those 5 customers, and 2-5 orderDetails for each new
order. Each new record in the business layer has been assigned a temporary
negative decrementing (-1, -2 ,etc..) PK value. Each FK is given the same
temporary value as the PK in the related table.
Now what should the data layer do as it receives all this updated data? I
know how to update the PK's properly, but how does each FK get the same
value as the related PK? Is it as easy as defining the Relationships
between the dataTables, do they all get updated as the PK in the related
table is updated?
My code currently works great for tables with GUID (uniqueidentifier) PK's,
since the PK's don't get updated by the DB. But I'm trying to get an option
that also works for int PK tables.
I'm just trying to determine at this point if I have to roll my own FK
update functionality. My data layer currently has separate classes for each
table. Each currently has their own internal DataSet, and DataAdapter. So
if relations are the cure, then I have some major restructuring to do. Or I
need to roll my own UpdateFKs() method to update the other objects in the
data layer.
IE.
class CustomerDB{
private DataSet _ds;
private DataAdapter _da;
//methods to select/update/insert/delete records in this table
// to see details look at one of the templates (01 to 05) on
// code generator project page (link below)
}
Any input is appreciated.
application. I've been able to get single tables to update correctly, and
have the database assigned key assigned to each DataRow. This is fine and
good for tables that don't have child records in other tables.
What do you do if in this situation:
table : "Order" with columns:
OrderID (int PK)
CustomerID (int FK)
Descriptor (nNarChar)
table: "OrderDetails" with columns:
OrderDetailsID (int PK)
OrderID (int FK)
ProductID (int FK)
Quantity (int)
also tables "Product" and "Customer" with PK's matching FK's above.
The business layer has been populated by querying the datalayer. In the
presentation layer the user adds 5 new customers (sales had a good day ,
10 new orders for those 5 customers, and 2-5 orderDetails for each new
order. Each new record in the business layer has been assigned a temporary
negative decrementing (-1, -2 ,etc..) PK value. Each FK is given the same
temporary value as the PK in the related table.
Now what should the data layer do as it receives all this updated data? I
know how to update the PK's properly, but how does each FK get the same
value as the related PK? Is it as easy as defining the Relationships
between the dataTables, do they all get updated as the PK in the related
table is updated?
My code currently works great for tables with GUID (uniqueidentifier) PK's,
since the PK's don't get updated by the DB. But I'm trying to get an option
that also works for int PK tables.
I'm just trying to determine at this point if I have to roll my own FK
update functionality. My data layer currently has separate classes for each
table. Each currently has their own internal DataSet, and DataAdapter. So
if relations are the cure, then I have some major restructuring to do. Or I
need to roll my own UpdateFKs() method to update the other objects in the
data layer.
IE.
class CustomerDB{
private DataSet _ds;
private DataAdapter _da;
//methods to select/update/insert/delete records in this table
// to see details look at one of the templates (01 to 05) on
// code generator project page (link below)
}
Any input is appreciated.