Insert Operation using ExecuteStoreCommand

Introduction

In this blog we will see how to perform insert 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_Insert   
  9. {  
  10.     class Program   
  11.     {  
  12.         static void Main(string[] args)   
  13.         {  
  14.             EmployeeEntities _dataContext = new EmployeeEntities();  
  15.             SqlParameter firstName = new SqlParameter("FirstName""Andy");  
  16.             SqlParameter lastName = new SqlParameter("LastName""Robes");  
  17.             (_dataContext as IObjectContextAdapter).ObjectContext.ExecuteStoreCommand("spInsertEmployee @FirstName, @LastName", firstName, lastName);  
  18.             _dataContext.SaveChanges();  
  19.             Console.ReadKey();  
  20.         }  
  21.     }  
  22. }  
Summary

In this blog we have seen how we can perform insert operation using executestorecommand. Happy coding!
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now