Are Multiple DataContext classes ever appropriate?

后端 未结 5 1959
别跟我提以往
别跟我提以往 2020-12-17 08:19

In order to fully use LinqToSql in an ASP.net 3.5 application, it is necessary to create DataContext classes (which is usually done using the designer in VS 2008). From the

5条回答
  •  臣服心动
    2020-12-17 08:33

    I think John is correct.

    "My main concern is that instantiating and disposing one huge DataContext class all the time for individual operations that relate to specific areas of the Database would be impose an unnecessary imposition on application resources"

    How do you support that statement? What is your experiment that shows that a large DataContext is a performance bottleneck? Having multiple datacontexts is a lot like having multiple databases and makes sense in similar scenarios, that is, hardly ever. If you are working with multiple datacontexts you need to keep track of which objects belong to which datacontext and you can't relate objects that are not in the same data context. That is a costly design smell for no real benefit.

    @Evan "The DataContext (or Linq to Entities ObjectContext) is more of a "unit of work" than a connection" That is precisely why you should not have more than one datacontext. Why would you want more that one "unit of work" at a time?

提交回复
热议问题