In this section, we will take a look at how we can perform some additional operations with the Entity SQL language. We will discuss the following:
Inserting a record using Entity SQL
Inserting a record with a foreign key constraint
Retrieving native SQL from EntityCommand
Transaction Management in Entity SQL
You can use Entity 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. Here is the code:
using (EntityConnection conn = new EntityConnection("Name=PayrollEntities")) { try { conn.Open(); EntityCommand 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...