开发者

Should I create multiple LINQ to SQL Classes Contexts in my projects

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?


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>();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜