Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6913379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:12:42+00:00 2026-05-27T09:12:42+00:00

My create and delete operations are working well. But, the Edit function is giving

  • 0

My create and delete operations are working well. But, the Edit function is giving the following error :- Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.

NOTE:- CatPicView is a ViewModel merging the two entities Category and Picture

Following is the code for my Edit action code :-

[HttpPost]
public ActionResult Edit(CatPicView catPic)
{
    if (ModelState.IsValid)
    {
        if (!String.IsNullOrEmpty(catPic.Picture.PictureUrl))
        {
            if (catPic.Category.PictureId == null)
            {
                Picture picture = new Picture();
                picture.PictureUrl = catPic.Picture.PictureUrl;
                db.Pictures.Add(picture);
                catPic.Category.PictureId = picture.Id;
            }
            else
            {
                db.Entry(catPic.Picture).State = EntityState.Modified;
            }
        }
        db.Entry(catPic.Category).State = EntityState.Modified;
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    ViewBag.ParentCategoryId = new SelectList(db.Categories, "Id", "Name", catPic.Category.ParentCategoryId);
    return View(catPic);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:12:43+00:00Added an answer on May 27, 2026 at 9:12 am

    Using the debuger, check the properties of the object you are trying to update. The most likely is that you have an ID in null.

    To fix this, you should place a hidden field holding the id of the modified object so when posting the form it became mapped to your object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a statement level trigger that fires whenever INSERT UPDATE or DELETE operations
I'm following this awful textbook, going through the basics of create/edit/delete records. The delete
Hello is possible to switch between DML commands/operations (Insert,Delete,Update) on Trigger Body?, I try
Q1.Can LINQ to Entity perform create, update or delete operations on a table without
I have YoutubeVideoService class which does CRUD(Create, Read, Update, and Delete) operations. In my
I'm using Exchange Web Services to Find, Create, Update, and Delete appointments from the
I have an asp.net Formview connected to an SQL datasource. When I create/edit/delete a
In oracle, I want to create a delete sproc that returns an integer based
I need to create Trigger for delete action which backsup all fields old value
I'm trying to create a cron job which will automatically delete .jpg files from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.