LINQ to SQL Tutorial
Lección 2 de 38 · Part 2 Insert Update Delete using LINQ to SQL · Bases de datos
Part 2 Insert Update Delete using LINQ to SQL
Text version of the video
http://csharp-video-tutorials.blogspot.com/2014/09/part-2-insert-update-delete-using-linq.html
Slides
http://csharp-video-tutorials.blogspot.com/2014/09/part-2-insert-update-delete-using-linq_4.html
LINQ to SQL Tutorial – All Text Articles & Slides
http://csharp-video-tutorials.blogspot.com/2014/09/linq-to-sql-tutorial.html
LINQ to SQL Tutorial Playlist
Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd
In this video, we will discuss performing Insert Update and Delete using LINQ to SQL. We will continue with the example, we worked with in Part 1. In Part 1, we discussed performing a Select using LINQ to SQL. Please watch Part 1 before proceeding.
Insert using LINQ to SQL
using (SampleDataContext dbContext = new SampleDataContext())
{
Employee newEmployee = new Employee
{
FirstName = “Tim”,
LastName = “T”,
Gender = “Male”,
DepartmentId = 1,
Salary = 55000
};
dbContext.Employees.InsertOnSubmit(newEmployee);
dbContext.SubmitChanges();
}
Update using LINQ to SQL
using (SampleDataContext dbContext = new SampleDataContext())
{
Employee employee = dbContext.Employees.SingleOrDefault(x =] x.ID == 8);
employee.Salary = 65000;
dbContext.SubmitChanges();
}
Delete using LINQ to SQL
using (SampleDataContext dbContext = new SampleDataContext())
{
Employee employee = dbContext.Employees.SingleOrDefault(x =] x.ID == 8);
dbContext.Employees.DeleteOnSubmit(employee);
dbContext.SubmitChanges();
}