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

  • Home
  • SEARCH
  • 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 3752200
In Process

The Archive Base Latest Questions

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

newbie writing, I’m new to MVC 2 C# and using EntityFramework with LINQ. In

  • 0

newbie writing, I’m new to MVC 2 C# and using EntityFramework with LINQ.

In many examples (including the MVC 2 MusicStore of Microsoft) I’ve noticed that the Database updates are made in the Controllers layers. For example If I want to update a Database Product I call to UpdateModel(product,”Products” ) and call to SaveChanges() in the ProductController class

Ok, simple and easy but is this following MVC “traditional” pattern ??

Instead of this, I try to delegate the responsibility to the ProductModel class (I’ve made it with success in Adding and Deleting with AutoMapper) but I don’t find the way to update from the model
I tried something like

        Mapper.CreateMap<Product, ProductModels>();
        Mapper.CreateMap<ProductModels, Product>();
        var p = Mapper.Map<Product, ProductModels>(prod);

        productosBD.AttachTo("Products", p); 
        productosBD.SaveChanges();

but no way…

Could somebody tell me how can I update an entity in the model layer??

Thanks in advance

  • 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-19T09:12:28+00:00Added an answer on May 19, 2026 at 9:12 am

    ASP NET MVC has evolved a lot from version 1 Beta to version 2 and now version 3 although 2 and 3 are much more similar.

    A lot of such samples are related to MVC 1 – something I learnt the hard way. I am pretty new to ASP NET MVC but realised in MVC 2, ModelBinder looks after updating the model so normally if you define your method signature as your model, you do not need to call UpdateModel.

    For example:

     public ActionResult Create(MyModel model)
     {
          ... // no need to call UpdateModel
    

    However if you define it like this, then you need to do that:

     public ActionResult Create(int id, FormCollection collection)
     {
          MyModel model = Repository.Get(id); // in your case EF productosBD.Where(x=>x.Id = id)
          UpdateMode(model, collection);
          Repository.Save(model);
    

    In terms of where the update happens, yes, it will happen in your controller but it depends if you use a Repository pattern or use the bare database context. I personally use a ServiceProxy which then talks to a WCF Service which talks to a Manager which uses a Repository to do that.

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

Sidebar

Related Questions

No related questions found

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.