I want update object with linq to entities, like this :
public ActionResult SubmitPool(SwimmingPool Pool)
{
SwimmingPool IsPool = (from sp in db.SwimmingPool
where sp.Id == Pool.Id
select sp).First();
if (IsPool != null) {
IsPool = Pool;
db.SaveChanges();
}
}
But It doesn’t…
If I does :
public ActionResult SubmitPool(SwimmingPool Pool)
{
SwimmingPool IsPool = (from sp in db.SwimmingPool
where sp.Id == Pool.Id
select sp).First();
if (IsPool != null) {
----> IsPool.Name = Pool.Name;
db.SaveChanges();
}
}
It does! But I want Update Full object. How do?
The line
does nothing to the data within; it simply changes the reference.
After that line, both
IsPoolandPoolpoint to the same object in the heap; not useful in your case.You have to specifically assign each member from one class to the other.