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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:17:06+00:00 2026-06-09T10:17:06+00:00

I’m working on an MVC3 project where I noticed that certain fields in the

  • 0

I’m working on an MVC3 project where I noticed that certain fields in the database are being set to null when that record is updated from the UI. This happens because those fields are not present on the form on post. I know this can be solved by adding HiddenFor entries for these, but that wouldn’t be a great approach since any new fields would need to be added there as well. I’m hoping to figure out a better solution.

A little elaboration on how the project is structured:

We have DTOs that match the EF entities exactly to simplify mapping. So the DTOs have every field present in the entities & database. We use the DTOs as our models.

The controllers pass the DTOs to a service layer. The service layer maps the DTO to its respective entity (using AutoMapper), and passes it to the persistence layer. The persistence layer is what actually uses the DbContext to save changes.

Say we have a Client DTO with a Name member and a FolderPath member, and a view that only has the Name member on its form. The form posts, and that FolderPath is null. That null value persists all the way to the update in the persistence layer. Somewhere along the line I have to specify that I don’t want that particular value overwriting what’s in the database.

From what I’ve gathered researching this on SO for about an hour, one approach might be…

  1. Keep the DTOs minimal in scope, for a specific set of fields that we
    know we will have on a form in a view.
  2. Tell AutoMapper to ignore
    anything that exists in the destination but not the source per this
    answer.
  3. In the service layer, when mapping the DTO to the
    entity, first retrieve the existing entity from the database. The
    mapping will only overwrite the members that are part of the DTO,
    and any other values will persist since they’re being retrieved from
    the database.

Would this be a valid approach? Are there any better or more common ways to address this problem?

  • 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-06-09T10:17:07+00:00Added an answer on June 9, 2026 at 10:17 am

    I would go with Option 1 and have view / html form specific models. It’s the cleanest solution, IMHO.

    There’s also the major issue that the other ways leave you open to hacking… i.e. if I knew other fields / properties on your model, I could craft a form post with that information and get it saved.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.