Since i can't comment on an answer i'll do it via a new answer..
I notice that your attribute is called "FirstName", are you by any chance trying to do this tutorial?
And is this the Edit action you're having problems with?
Because this is the exact same problem me and 2 of my classmates are having.
Here is a more detailed explanation of the problem:
This is the controller action:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Contact contactToEdit) {
if (!ModelState.IsValid)
return View();
try {
var originalContact = (from c in base._entities.ContactSet
where c.Id == contactToEdit.Id
select c).First();
base._entities.ApplyPropertyChanges(originalContact.EntityKey.EntitySetName, contactToEdit);
base._entities.SaveChanges();
return RedirectToAction("Index");
} catch(Exception e) {
return View();
}
}
When the ApplyPropertyChanges is called an exception is raised. (InvalidOperationException)
Exception message:
{System.InvalidOperationException: The ObjectStateManager does not contain an ObjectStateEntry with a reference to an object of type 'ContactManager.Models.Contact'.
at System.Data.Objects.ObjectContext.ApplyPropertyChanges(String entitySetName, Object changed)
at ContactManager.Controllers.HomeController.Edit(Contact contactToEdit) in C:\Users\Jeroen\Desktop\ContactManager\ContactManager\ContactManager\Controllers\HomeController.cs:line 65}
When I add this line before ApplyPropertyChanges:
System.Data.Objects.ObjectStateEntry x = base._entities.ObjectStateManager.GetObjectStateEntry(originalContact);
x does contain an entry of the correct type. (debug image)
Note: I made a small deviation from the tutorial and put the entities object in a superclass so I don't have to declare the same object in all my controllers. But the same problem arises when following the tutorial.