Entity framework UPDATE

Sep 5 2011 5:00 PM
Hi,
I have simple update method and have problem with it.

public ReturnCodes UpdateProduct(Product product)
        {
            try
            {
                dbObjects db = new dbObjects();
                Product pro = db.Products.FirstOrDefault(t => t.UniqueID == product.UniqueID);
                pro = product;
                int i = db.SaveChanges();
                return ReturnCodes.SUCCESS;
            }
            catch (Exception exc)
            {
                return ReturnCodes.SYSTEM_ERROR;
            }
        }
But variable i is 0 so it means that no record is affected. When i change the line

pro = product;

with

pro.name = product.name;
pro.price = product.price;
.....

it works just fine. New to entity framework so pls give me some explanation.



Answers (1)