Linq to SQL: Is it better to have a small DataContext for each page or a global one?

前端 未结 4 539
情深已故
情深已故 2021-01-12 03:08

I am trying out Linq to SQL in an ASP.NET application that uses a large database with lots of foreign keys (100+ tables). I am impressed with how Linq permits you to create

4条回答
  •  长情又很酷
    2021-01-12 03:23

    I did a test on our database which has about 600 tables. First, I broke them up into 9 discrete data contexts which were each pretty manageable. Then I wrote a script which selected, updated, and deleted a few hundred times on one of them (disposing of the datacontext after each one, so that LINQ was forced to recreate it for each access).

    Then I made another datacontext that had all 600 tables right on it - and ran the same test.

    The results were virtually identical. My conclusion was there was no performance gain to be had from the smaller datacontexts. And it is certainly much easier to work with entities that came from a single datacontext (not in the designer view though -- phew!).

提交回复
热议问题