Introduction
In this blog we will see how to perform insert 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_Insert
- {
- class Program
- {
- static void Main(string[] args)
- {
- EmployeeEntities _dataContext = new EmployeeEntities();
- SqlParameter firstName = new SqlParameter("FirstName", "Andy");
- SqlParameter lastName = new SqlParameter("LastName", "Robes");
- (_dataContext as IObjectContextAdapter).ObjectContext.ExecuteStoreCommand("spInsertEmployee @FirstName, @LastName", firstName, lastName);
- _dataContext.SaveChanges();
- Console.ReadKey();
- }
- }
- }
Summary
In this blog we have seen how we can perform insert operation using executestorecommand. Happy coding!