views:

30

answers:

1

This is a design question, I noticed that by time by LINQ-to-SQL Context gets crowded with all the tables from the database, so today I wanted to create a new context for the new tables I added recently. The tables makes up a unit of logic by themselves and they are separated from other tables logically, except for 2 tables. I am planning to redundant those tow tables and put them again in the new context.

My question is that is my design valid, what problems I will face which I am not considering now?

A: 

You can certainly do that, but make sure you don't share any tables between the two Contexts. What you need to watch out for are situations where you need both DataContext instances. In other words if you are adding or editing in two contexts at the same time you need to remember to save changes in both. If rows are shared between the two contexts you can lose changes.

Also remember that you don't need to use the LINQ to SQL designer's contexts at all. You can always do

DataContext context = new DataContext();
Table<SomeL2SClass> table = context.GetTable<SomeL2SClass>();
Mike Two
thanks for the answer, I am paying attention to concurrency problem, it is not my concern since the tables that I am sharing I don't use them to manipulate data. it is only to read data.
Jamal
@Jamal - Then what you are trying to do should work. It seems like a good idea to keep the different units separated.
Mike Two