View Single Post
  #1 (permalink)  
Old March 27th, 2009, 01:36 PM
softwarea softwarea is offline
Registered User
 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic DataContext?

Hi Vince,

I just got your book a couple of days ago and I really like how everything engages with each other. However I have a question concerning the DataContext in the DAL.

Though I'm still in chapter 4 I assume that sooner or later you will add every table in your database to the HRPaidTimeOffDataContext. Creating classes like ENTUserAccountData for every table ensures that every entity object knows how to insert, update or delete itself in the database. So far so god.

My problem is that all code in the DAL classes is using ONE DataContext (HRPaidTimeOffDataContext). What if your application would have more than one DataContext class?

Here is a scenario why I'm interested in that: Imagine you had two different customers who would both want to use your application. Instead of setting up two separate platforms (2 applications + 2 databases) you want to be smart and have rather one application for both of them. You would set up two databases though, one for each customer. The two databases would be pretty similar but not equal, because every customer has his special requirements. In the end you would probably have at least two DataContext classes like "EverybodysDataContext" and "CustomerSpecificDataContext". The tables that both customers have in common go in the EverybodysDataContext, the other tables go in the CustomerSpecificDataContext. Now that you have two or more DataContexts you would still want that any ENTBaseData object knows how to handle the CRUD operations, right? But the declaration of the ENTBaseData class refers to one concrete DataContext.

Do you see any way to have the type of DataContext being dynamic in your base classes? In other words: no matter how many DataContexts my application would have, all my entites could still inherit from ENTBaseData.

I realize this can not be answered with a simple Yes or No. And in case I didn't simplify the problem enough, please feel free to ask. But I would appreciate any suggestion you had for me.

Thanks!
Ingmar