In order to select data from a Model
using the ADO.Net Entity Data Model, we should first create an ADO.Net Entity
Data Model class, refer to the post Creating your First ADO.Net Entity Data Model
to see on how to create an ADO.Net Entity Data Model, that maps to the physical
database.
Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model to select data. In this post we shall see on how to use the ADO.Net Entity Data Model to DELETE a record in the Employee table.
ht:
normal;mso-layout-grid-align:none;text-autospace:none'>objEmployee.Salery = 7500;
Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model to select data. In this post we shall see on how to use the ADO.Net Entity Data Model to DELETE a record in the Employee table.
1. Create an Object of the ADO.Net
Entity Data Model class
2. Get the Object of the Employee whose details needs to be Deleted
3. Delete the Object
4. Commit changes to the Model
Here is the code to DELETE rows using the ADO.Net Entity Data Model
EmployeesEntities dbContext = new EmployeesEntities();
2. Get the Object of the Employee whose details needs to be Deleted
3. Delete the Object
4. Commit changes to the Model
Here is the code to DELETE rows using the ADO.Net Entity Data Model
EmployeesEntities dbContext = new EmployeesEntities();
//
// Get The
Object of the Selected Employee
Employee
objEmployee = (from emp in dbContext.Employee
where emp.ID == 235
select emp).First();
//
// Delete the
Employee Object and Save the Detils.
dbContext.DeleteObject(objEmployee);
dbContext.SaveChanges();
5. Once we execute the code, a record for the Employee with ID 235 will get deleted from the Employee Table.
5. Once we execute the code, a record for the Employee with ID 235 will get deleted from the Employee Table.
//
// Save the
Employee Details
dbContext.SaveChanges();
5. Notice that we are referring to the Departments object to get the DepartmentID value for the Employee table.
6. Once we execute the code, a new record for the Employee Tom will get updated in the Employee Table.
5. Notice that we are referring to the Departments object to get the DepartmentID value for the Employee table.
6. Once we execute the code, a new record for the Employee Tom will get updated in the Employee Table.
Related Post
Concepts
ADO.NET Entity Framework
ADO.NET Entity Framework Architecture
Entity Data Model
LINQ To SQL Vs ADO.Net Entity Framework
Programming
ADO.Net Entity Data Model Prerequisite
Creating your First ADO.Net Entity Data Model
Selecting Data using ADO.Net Entity Framework
Selecting Data by Joining Tables using ADO.Net Entity Framework
Inserting Data using ADO.Net Entity Framework
Inserting Data with Foreign Key Reference using ADO.Net Entity Framework
Updating Data using ADO.Net Entity Framework
Updating Data with Foreign Key Reference using ADO.Net Entity Framework
Deleting Data using ADO.Net Entity Framework
Concepts
ADO.NET Entity Framework
ADO.NET Entity Framework Architecture
Entity Data Model
LINQ To SQL Vs ADO.Net Entity Framework
Programming
ADO.Net Entity Data Model Prerequisite
Creating your First ADO.Net Entity Data Model
Selecting Data using ADO.Net Entity Framework
Selecting Data by Joining Tables using ADO.Net Entity Framework
Inserting Data using ADO.Net Entity Framework
Inserting Data with Foreign Key Reference using ADO.Net Entity Framework
Updating Data using ADO.Net Entity Framework
Updating Data with Foreign Key Reference using ADO.Net Entity Framework
Deleting Data using ADO.Net Entity Framework
No comments:
Post a Comment