0
 public ReturnMessage EditCategories(Category objCategory)
    {


        ReturnMessage objReturnMessage = new ReturnMessage();
        try
        {
            Category objCategoryNew = db.Categories.Where(x => x.CategoryId == objCategory.CategoryId).FirstOrDefault();
            if (objCategoryNew != null)
            {
                objCategoryNew = objCategory;
                db.SaveChanges();
                objReturnMessage.isSuccessfull = true;
                objReturnMessage.responseMessage = "Successfully updated.";
            }
            else
            {
                objReturnMessage.isSuccessfull = false;
                objReturnMessage.responseMessage = "Category not present.";
            }
        }
        catch (Exception ex)
        {
            objReturnMessage.isSuccessfull = false;
            objReturnMessage.responseMessage = ex.Message;
        }
        return objReturnMessage;

    }

すべてがうまくいき、例外はありませんが、データはまだ更新されていません。何が問題なのかわからない。助けてください?

4

1 に答える 1

2

The line:

objCategoryNew = objCategory;

will not work out since you change the reference objCategoryNew to objCategory, not the object itself, what you have to do is to assign each property of objCategory to objCategoryNew, something like:

objCategoryNew.Pro1 = objCategory.Pro1;
objCategoryNew.Pro2 = objCategory.Pro2;
....
于 2013-08-14T10:40:40.837 に答える