Performing CRUD operations on objects
In this section, we will discuss how you can use Object Services to add, modify, and delete an object within ObjectContext.
Adding an object to the ObjectContext class requires the use of the AddObject method. It accepts the entity set name and entity instance as parameters and adds the object passed to it to the ObjectContext class. Once you have added an object to the ObjectContext class, you can call SaveChanges to persist the changes to the database.
Here is an example that shows how you can add an object to the ObjectContext class and then call the SaveChanges method to persist the changes to the database:
SecurityDBEntities dbContext = new SecurityDBEntities();
using (ObjectContext objectContext =
((IObjectContextAdapter)dbContext).ObjectContext)
{
UserLoginHistoryvar userLoginHistory = new
UserLoginHistory();
userLoginHistory.UserID = 1;
userLoginHistory...