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 6977671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:39:20+00:00 2026-05-27T17:39:20+00:00

I am learning ASP.NET MVC and Entity Framework. After I learning from this web

  • 0

I am learning ASP.NET MVC and Entity Framework.

After I learning from this web references, I think that when we want to make update process,

  1. we need to remove existing record first
  2. then insert new record.

My code:

public List<UserModel> _usrList = new List<UserModel>();

public void Update(UserModel umToUpdate)
{
        foreach (UserModel um in _usrList)
        {
            if (um.UserName == umToUpdate.UserName)
            {
                _usrList.Remove(um);
                _usrList.Add(umToUpdate);
                break;
            }
        }
    }

When we were doing in traditional way, we can update data without removing it.

(eg. update tablename set column = value where columnname = value)

So now I am searching for the way to make update process without removing original rows.

Is this possible in Entity Framework?

Please let me know the way.

  • 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-27T17:39:21+00:00Added an answer on May 27, 2026 at 5:39 pm

    That example is about creating views, and client side validation, sadly the server side part (IMO) is bad. Bad in the sense, that it creates confusion…
    You are right, you shouldn’t do that with a real database.

    But there are EF examples on the asp.net site: http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application

    Answers:

    In the example you give me show that context.Entry(student).State = EntityState.Modified; is that all we need to do when we need to do update ? please explain me again.

    Almost, that line tells EF that that record is updated, and these are the current values. Right now changes are only in the server’s memory. You actually save the changes back to the database by issuing the db.SaveChanges(); command. The rest is handled by EF. See the "Creating an Edit Page" section in the example.

    if so, don’t we need to remove existing record first ?

    Nope, sadly the first example without a db is confusing. When I first saw that, I thought "WTF is that guy smoking?". Just to figure out that it is an official sample…

    and then, Don’t we need to give any condition parameters to make update process ?

    Don’t have to do it explicitly, because MVC’s model binding takes care of reading up all values (including the PersonID in a hidden field) from the posted data. The ID of the current record is in a html hidden field, so MVC knows which record you are updating. For Example: Views\Students\Edit.cshtml row 17:

    @Html.HiddenFor(model => model.PersonID)
    

    And everything works "automagically".

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

Sidebar

Related Questions

I'm learning ASP.NET MVC Framework, From some articles like this , it seems that
I'm learning ASP.NET MVC 3 with Entity Framework Code First. I'm following a tutorial
I am learning ASP.NET MVC and Entity Framework Code First, LINQ by creating a
I am learning ASP.NET MVC now a days and I have found that most
I am playing with learning ASP.NET MVC as a non-web developer. I am trying
I came from PHP language(codeigniter), but now I learning ASP.Net MVC :) In PHP
I'm a .NET Developer, primarily using c#, asp.net mvc, entity framework and programming for
I've been learning the ASP.NET MVC framework using the Apress book Pro ASP.NET MVC
I have been learning ASP.NET MVC in the last few months and I think
I am just learning ASP.Net's MVC framework and so my question is likely basic.

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.