none
Is there any framework for LINQ-To-SQL DataContext pooling? RRS feed

  • Question

  • Hello!

    I'm trying to find the right way to control LINQ-To-SQL DataContext usage in big Sharepoint 2010-based web-applications, using custom databases (on SQL Server 2008 R2).

    Ways to create new DataContext for each operation with DB or creating disposable classes, which use one context for all operations with DB, implemented inside, are not enough effective for some reasons.

    So now I'm searching for a way to create and control something like pool of DataContext - one for user. The main question is correct disposing of DataContexts and closing connection.

    Of course, custom version can be created, but maybe there already are some solutions?


    Thursday, January 30, 2014 11:20 AM

All replies

  • Hi Quanzi,

    >Of course, custom version can be created, but maybe there already are some solutions?

    First of all, you don’t really need to dispose them in most cases- and that’s by design. I personally prefer to do so anyway, as it’s easier to follow the rule of “dispose of everything which implements IDisposable” than to remember a load of exceptions to it – but you are unlikely to leak a resource if you do forget to dispose of it.

    LINQ to SQL only supports 1 to 1 mapping of database tables, views, sp in Microsoft SQL Server. It’s a great API to use for quick data access. But we have an ORM API which allows for a broad definition of object domain models and their relationships to many different ADO.NET data providers. It’s Entity Framework. I think Entity is a more advanced version of LINQ to SQL.

    Please refer to the following link for more information about Entity.

    http://msdn.microsoft.com/en-US/data/ee712907.

    Hope useful to you.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 31, 2014 4:53 AM
    Moderator
  • Thank you for your response. I know about Entity Framework, but Sharepoint 2010 uses .NET 3.5, so it's contains less functions than LINQ to SQL, and we prefer not using Entity Framework.

    About not disposing context it's the same issue - the best way is to dispose everything disposable, I think.

    The problem of searching for datacontext pooling framework is also consiquence of this points.

    Friday, January 31, 2014 7:42 AM
  • Hi Quanzi,

    I found the following helpful in deciding a data context management strategy. Please refer to the following link. http://weblog.west-wind.com/posts/2008/Feb/05/Linq-to-SQL-DataContext-Lifetime-Management.

    Hope useful to you.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 5, 2014 8:45 AM
    Moderator
  • Thank you very much, but there is the same question about that article, about the thread specific datacontexts: if this contexts aren't disposed by developer, the would live while thread is up? When they will be disposed? When user session in Sharepoint will be ended?

    Wednesday, February 5, 2014 1:16 PM
  • An object will exist while the context of the object is current. When it is out of scope it will get marked for garbage collection. When and how the resources get released is up to the garbage collector. IDisposable is mainly to dispose of unmanaged resources. Remember, C# is a managed language so for the most part memory management is automatic.
    Thursday, February 13, 2014 6:01 PM