When does the DataContext will open a connection to the DB?

Posted by Eran Betzalel on Stack Overflow See other posts from Stack Overflow or by Eran Betzalel
Published on 2009-09-16T16:23:02Z Indexed on 2010/03/12 10:57 UTC
Read the original article Hit count: 187

I am using L2S to access my MSSQL 2008 Express server. I would like to know when the DataContext will open a connection to the DB? and will it close the connection right after it opened it?

For example:

var dc = new TestDB();  // connection opened and closed?

dc.SomeTable.InsertOnSubmit(obj);  // connection opened and closed?

foreach(var obj in dc.SomeTable.AsEnumerable())  // connection opened and closed?
{
    ...  // connection opened and closed?
}

dc.SubmitChanges();     // connection opened and closed?

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about sql-server-2008