I am using this code sample from here.. http://msdn.microsoft.com/en-us/data/gg685489
[HttpPost]
public ActionResult Edit(int id, Blog blog)
{
try
{
using (var db = new BlogDataEntities())
{
db.Entry(blog).State = System.Data.EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
I am having difficulty in implementing the above code – the example assumes using EF 4.1 and I was on older version. I later upgraded my EF version to 4.3 and I still am not able to do this. I accessed nuget package and installed it from there. I checked the references and EF version is comfirmned to be 4.3… even after the new install of EF, intellisense does not show me the “db.entry” option….can any one tell me if if i am missing another step here… thank you.
If you are not using Code First, then the default data context is ObjectContext (rather than DbContext which your code is designed to use). If you are using ObjectContext then you’ll want to do this instead:
http://msdn.microsoft.com/en-us/library/bb896248.aspx
However I recommend right clicking in your model and ‘add code generation item’ and add the DbContext template. This will then convert your object context into dbcontext and allow you to access entry as you are trying to code it. Either one will work, but DbContext has a much easier API to work with.