why entity framework code first open close 4 different database connection for a single INSERT? -


i inserting row in table in ef code first scenarios, while m checking log, can see 4 different open/close connection , related activity.

i think, it's default behavior of ef.

could tell me more regarding this???

var ninja = new ninja         {             name = "sampsonsan",             servedinoniwaban = false,             dateofbirth = new datetime(2008, 1, 28),             clanid = 1         };          using (var context = new ninjacontext())         {             context.database.log = console.writeline;              context.ninjas.add(ninja);             context.savechanges();         } 

log

1. opened connection @ 10/3/2015 11:18:45 +05:30

select count(*) information_schema.tables t t.table_schema + '.' + t.table_name in     ('dbo.clans','dbo.ninjaequipments','dbo.ninjas') or t.table_name = 'edmmetadata' 

-- executing @ 10/3/2015 11:18:45 +05:30

-- completed in 12 ms result: 3 closed connection @ 10/3/2015 11:18:45 +05:30

2. opened connection @ 10/3/2015 11:18:46 +05:30

 select [groupby1].[a1] [c1] ( select     count(1) [a1]     [dbo].[__migrationhistory] [extent1]     [extent1].[contextkey] = @p__linq__0 )  [groupby1] 

-- p__linq__0: 'datamodel.migrations.configuration' (type = string, size = 4000)

-- executing @ 10/3/2015 11:18:47 +05:30

-- completed in 34 ms result: sqldatareader closed connection @ 10/3/2015 11:18:47 +05:30

3. opened connection @ 10/3/2015 11:18:47 +05:30

select top (1) [project1].[c1] [c1], [project1].[migrationid] [migrationid], [project1].[model] [model], [project1].[productversion] [productversion] ( select     [extent1].[migrationid] [migrationid],     [extent1].[model] [model],     [extent1].[productversion] [productversion],     1 [c1]     [dbo].[__migrationhistory] [extent1]     [extent1].[contextkey] = @p__linq__0 )  [project1] order [project1].[migrationid] desc 

-- p__linq__0: 'datamodel.migrations.configuration' (type = string, size = 4000)

-- executing @ 10/3/2015 11:18:47 +05:30

-- completed in 25 ms result: sqldatareader

closed connection @ 10/3/2015 11:18:47 +05:30

4. opened connection @ 10/3/2015 11:18:47 +05:30

started transaction @ 10/3/2015 11:18:47 +05:30

insert [dbo].[ninjas]([name], [servedinoniwaban], [clanid], [dateofbirth]) values (@0, @1, @2, @3) select [id] [dbo].[ninjas] @@rowcount > 0 , [id] = scope_identity() 

-- @0: 'sampsonsan' (type = string, size = -1)

-- @1: 'false' (type = boolean)

-- @2: '1' (type = int32)

-- @3: '1/28/2008 12:00:00 am' (type = datetime2)

-- executing @ 10/3/2015 11:18:47 +05:30

-- completed in 131 ms result: sqldatareader

committed transaction @ 10/3/2015 11:18:48 +05:30

closed connection @ 10/3/2015 11:18:48 +05:30


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -