I really checked this thing for both ADO.net and EF v.6 and looked at the joins in the SQL table
select * from sys.dm_exec_connections
Test methods should look like this:
1) ADO.net using
using(var Connection = new SqlConnection(conString)) { using (var command = new SqlCommand(queryString, Connection)) { Connection.Open(); command.ExecuteNonQueryReader(); throw new Exception()
2) ADO.net using
var Connection = new SqlConnection(conString); using (var command = new SqlCommand(queryString, Connection)) { Connection.Open(); command.ExecuteNonQueryReader(); throw new Exception()
1) EF using.
using (var ctx = new TestDBContext()) { ctx.Items.Add(item); ctx.SaveChanges(); throw new Exception()
2) EF without using
var ctx = new TestDBContext(); ctx.Items.Add(item); ctx.SaveChanges(); throw new Exception()
I do not know why this is so, but EF automatically closes the connections. Also, all repository and UnitOfWork templates that use EF do not use usage. This is very strange for me, because DBContext is a one-time type, but it is a fact.
Perhaps they did something new at Microsoft for processing?
Artem G Nov 07 '13 at 21:20 2013-11-07 21:20
source share