Introduction
In this blog we will see how to perform update operation using executestorecommand.
Program.cs
- using System;
- using System.Collections.Generic;
- using System.Data.Entity.Infrastructure;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ExecuteStoreCommand_Update
- {
- class Program
- {
- static void Main(string[] args)
- {
- EmployeeEntities _dataContext = new EmployeeEntities();
- SqlParameter empId = new SqlParameter("EmpId", "1");
- SqlParameter firstName = new SqlParameter("FirstName", "Andy");
- SqlParameter lastName = new SqlParameter("LastName", "Robes");
- (_dataContext as IObjectContextAdapter).ObjectContext.ExecuteStoreCommand("spUpdateEmployee @EmpId, @FirstName, @LastName", empId, firstName, lastName);
- _dataContext.SaveChanges();
- Console.ReadKey();
- }
- }
- }
Summary
In this article we have seen how we can perform update operation using executestorecommand. Happy coding!