This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) | |
{ | |
using (var conn = new System.Data.SqlClient.SqlConnection(_connectionstring)) | |
{ | |
conn.Open(); | |
using (Context context = new Context(conn, false)) | |
{ | |
context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [dbo].[TableName] ON"); | |
context.TableName.AddRange(items); | |
context.SaveChanges(); | |
context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [dbo].[TableName] OFF"); | |
scope.Complete(); | |
} | |
} | |
} |
No comments:
Post a Comment