Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to insert value to identity column using entity framwork

using (var dataContext = new DataModelContainer())
using (var transaction = dataContext.Database.BeginTransaction())
{
    var user = new User()
    {
        ID = id,
        Name = "John"
    };

    dataContext.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[User] ON");

    dataContext.User.Add(user);
    dataContext.SaveChanges();

    dataContext.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[User] OFF");

    transaction.Commit();
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: pause unity game 
Csharp :: unity getcomponent 
Csharp :: convert pdf to image c# 
Csharp :: disabling a button if textbox is empty c# 
Csharp :: c# normalize value 
Csharp :: JsonConvert.DeserializeObject options camelcasing c# .net 
Csharp :: append an array in c# 
Csharp :: finally c# code 
Csharp :: how to turn on/off Particle System unity 
Csharp :: return an interface or a class C# 
Csharp :: c# comment 
Csharp :: npm add auth token 
Csharp :: vb.net check if datatable has rows 
Csharp :: string c# 
Csharp :: unity detect when an object has been clicked 
Csharp :: c# if isset 
Csharp :: C# program lambda Func 
Csharp :: how to decrease velocity of a Unity rigidbody 
Csharp :: c# check if object is of any generic type 
Csharp :: .net on vs code 
Csharp :: C# System.nanoTime 
Csharp :: push c# array 
Csharp :: start a particle effect when a button is pushed 
Csharp :: c sharp convert string time into 24 hours time 
Csharp :: Rotating an object in Unity usign Physics 
Csharp :: how to exit winforms application and shutdown pc in c# 
Csharp :: join string c# 
Csharp :: c# try parse date yyyymmdd 
Csharp :: unity2d switch camera 
Csharp :: c# networkstream read all bytes 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =