LINQ to SQL multiple DataContext-s -
i'm trying figure best strategy how organize datacontexts. typical db work has between 50 , 100 tables in third-normal form , many relations between them. think have 2 options:
- put tables in single context. ensure committed in correct order in database. problem linq designer mess 50+ tables , i'm worrying performance may affected.
- create several data contexts based on logical grouping of tables. problem there places 1 side of relation in 1 context , other in one. we'll have manually take care of committing both context-s in correct order.
is there recommended practice handle this?
more details:
i want create own entities , unit of work on top of linq sql. entities defined in xml model file mapping linq entities specified also. custom tool generate entities (poco) based on model. client code interact entities , unit of work; never directly datacontext or linq entities. not want duplicate linq sql provide out of box want use underlying linq datacontext. means cannot have 2 orders in different data contexts, because wouldn't possible map poco order both of them.
this common question has been thoroughly analyzed here: http://craftycode.wordpress.com/2010/07/19/linq-to-sql-single-data-context-or-multiple/
in essence, should create @ 1 data context per connected group of tables, or 1 data context per database.
Comments
Post a Comment