Other operations with E-SQL
In this section, we will take a look at how we can perform some additional operations with the E-SQL language. We will discuss the following:
Inserting a record using E-SQL
Inserting a record with a foreign key constraint
Retrieving native SQL from
EntityCommandTransaction management in E-SQL
Inserting a record using E-SQL
You can use E-SQL statements and easily perform CRUD operations. Let's assume that you have a stored procedure called InsertDesignation and you would like to use it to store a record in the designation table of your Payroll database. This is the code:
using (EntityConnection var conn = new EntityConnection("Name=PayrollEntities"))
{
try
{
conn.Open();
EntityCommandvar cmd = conn.CreateCommand();
cmd.CommandText = "PayrollEntities.Employee_Insert";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("FirstName", "Joydip");
cmd.Parameters.AddWithValue("LastName", "Kanjilal");
cmd.Parameters.AddWithValue...