OO Programming and Relational Databases - please help!

R

Rob Thomas

Hi,

I have a couple of classes:

Customer, Contact, ContactList, Agency, HostingCustomer and
OtherCustomer.

The Customer class is a base class and contains all the common
properties and methods associated with the customer including methods
such as Add, Delete and Get.

The Agency, HostingCustomer and OtherCustomer classes inherit from the
Customer Class and provide additional properties and methods specific to
those types of customers. They also override the Add, Delete and Get
methods of Customer in which they call the base methods first and then
perform additional tasks.

The ContactList class implements (amongst other things) ICollection to
act as an ArrayList of Contact objects and like the Customer class, the
Contact class contains methods such as Add, Update and get etc. There is
a property of type ContactList in the customer class to hold a
collection of contacts for the customer.

Using this model, I am able to itterate through the ContactList in the
Customer class and call the Add method of each Contact contained within
the list by means of Polymorphism - which I like.

My problem occurs when I want to use transactions with the data. For
example, I don't want to add a new customer to the database if there was
a problem with one of the contacts - I'd like to roll back the
transaction. My question is how would I manage transactions in this sort
of model/environment ?

Any help or advice would be welcomed.

Thanks,
Rob
 
N

Nicholas Paldino [.NET/C# MVP]

Rob,

In this situation, you would have your objects listed as requiring a
transaction. This way, if a transaction doesn't exist, it would create a
new one. If it was already in the context of another transaction, then it
would join that context and be able to vote on its outcome.

Hope this helps.
 
T

Thomas Tomicek [MVP]

Did you ever ytry looking ant O/R mappers?

They allow you to write code in EAXACTLY this fashion and handle al the
nifty details for you - reducing your coding efforts by about 40% for these
classes.

AND they handle all this stuff like transactions :)

There are a couple of them - like the EntityBroker :)
(http://www.thona-consulting.com/, under Products)

--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top