You are implementing a method that uses Entity Framework to insert a Product entity. You add the following code:

public void InsertProduct(Product product)
using (AdventureWorksEntities context = new AdventureWorksEntities())


When you execute the code, you find that the product is not inserted. You need to modify the code to ensure that the product is inserted.

What should you do ?

 Posted by Rajkatie on 9/30/2012 | Category: ADO.NET Interview questions | Views: 2755 | Points: 40
Select from following answers:
  1. Call the ObjectContext's method Refresh method before calling SaveChanges.
  2. Call the ObjectContext's method AcceptAllChanges method before calling SaveChanges.
  3. Replace the call to Attach with a call to the ObjectContext's AddObject method and After attaching the updated product, call the ChangeObjectState method of the ObjectContext's ObjectStateManager. Set the EntityState to Added.
  4. All Above

Show Correct Answer

Source: MeasureUp.Com | | Alert Moderator 

Comments or Responses

Login to post response