Problem with EDM in ASP.NET MVC
Posted
by Mannsi
on Stack Overflow
See other posts from Stack Overflow
or by Mannsi
Published on 2009-08-14T13:15:23Z
Indexed on
2010/04/29
6:17 UTC
Read the original article
Hit count: 386
Hello,
I have a question that is pretty similar to this question:
http://stackoverflow.com/questions/899734/strongly-typed-asp-net-mvc-with-entity-framework
but the solutions for that question don't work for me. Let me start by saying that I don't know a great deal about the subject I am asking about.
I have the following code
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(PaymentInformation paymentInformationToEdit, int pensionFundID)
{
var originalPaymentInformation = (from PIs in _db.PaymentInformation
where PIs.employeeNumber == paymentInformation.employeeNumber
select PIs).First();
var laborUnion = (from LUs in _db.LaborUnion
where LUs.laborUnionID = laborUnionID
select LUs)First();
paymentInformationToEdit.laborUnion = laborUnion;
_db.ApplyProperyChanges(originalPaymentInformation.EntityKey.EntitySetName, paymentInformationToEdit);
_db.SaveChanges();
}
I get an error when I try for the ApplyProperyChanges saying 'The existing object in the ObjectContext is in the Added state. Changes can only be applied when the existing object is in an unchanged or modified state'.
I don't know how to change the state to either, or even if I am doing something fundamentally wrong. Please advice.
EDIT: I hope this is the way to go here on stackoverflow. I haven't gotten an answer that solved my problem but Gregoire below posted a possible solution that I didn't understand. I hope this edit bumps my question so somebody will see it and help me. Sorry if this is not the way to go.
© Stack Overflow or respective owner