Update Operation using ExecuteStoreCommand

Introduction

In this blog we will see how to perform update operation using executestorecommand.

Program.cs

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Data.Entity.Infrastructure;  
  4. using System.Data.SqlClient;  
  5. using System.Linq;  
  6. using System.Text;  
  7. using System.Threading.Tasks;  
  8. namespace ExecuteStoreCommand_Update   
  9. {  
  10.     class Program   
  11.     {  
  12.         static void Main(string[] args)   
  13.         {  
  14.             EmployeeEntities _dataContext = new EmployeeEntities();  
  15.             SqlParameter empId = new SqlParameter("EmpId""1");  
  16.             SqlParameter firstName = new SqlParameter("FirstName""Andy");  
  17.             SqlParameter lastName = new SqlParameter("LastName""Robes");  
  18.             (_dataContext as IObjectContextAdapter).ObjectContext.ExecuteStoreCommand("spUpdateEmployee @EmpId, @FirstName, @LastName", empId, firstName, lastName);  
  19.             _dataContext.SaveChanges();  
  20.             Console.ReadKey();  
  21.         }  
  22.     }  
  23. }
Summary

In this article we have seen how we can perform update operation using executestorecommand. Happy coding!
Next Recommended Reading Update DataTable using LinQ

MVC Corporation
MVC Corporation is consulting and IT services based company.