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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:58:19+00:00 2026-05-18T19:58:19+00:00

I am building a ASP.NET MVC application where I use the following flow :

  • 0

I am building a ASP.NET MVC application where I use the following flow :

Get Entity

  1. Run Action at a controller
  2. Fetch data from FactoryClass that operates against the Model(Entity Framework)
  3. Get data back to the Action in the controller
  4. Use AutoMapper to translate from Model object to ModelView object
  5. Return the ModelView object to the strongly typed View

Update Entity

  1. Run Action with ModelView Entity as input (DefaultDataBinder will be used)
  2. Validate ModelView Entity
  3. Send the ModelView object direcly to the right factory method.
  4. Check if the ModelView object has id and if so fetch the Model object from database
  5. Use AutoMapper to translate the incoming ModelView object to a Model object/entity. If its a update, then use the fetched Model object as destination.
  6. If it is a update use Refresh Client.Wins else use Add
  7. Run SaveChanges and return to the controler.

Problem 1

The ModelView classes is special made for the views that the controler actions is connected to (it could contain both edeting objects and lists). It´s common that several actions with diffrent views uses the same ModelView Class, that means that not all objects in the ModelView object will be used in every action/view.

As long as the View uses all the properties of ModelViewObjects that can be updated there is no problem but…

Say that we got a View where some of the properties of the ModelViewObject is not used, this ModelViewObject is sent to the factory(to be updated) where the corsponding ModelObject is fetched(from db/entity framework) and then merged with the ModelViewObject with AutoMapper. The problem here is that properties on the ModelViewObject that is not set(not used in the view) will result in a overwrite of real data in the ModelObject.

To solve this u usually use AutoMapper ForMember Ignor(), but this will be a problem when a complete ModelViewObject(all properties set) will update db.

How do you handle this? Do you have diffrent Update methods in the factorys where diffrent AutoMapper setting?

It would be nice If I could only have a method like this : UpdateMyEnityt(MyEntity entity) and this methid will update och add MyEntity object.

Problem 2

Where should I place the AutoMapper mappings? So far I have placed Updates in the factory and Get in the controller. I have thought of placeing the mappings in the ModelViewObject for example ModelViewObject.ToDataModel but if I do not need a complete translate(som properties is to be ignored) then I will have to do this AutoMapper else where.

How do you handle this?

Problem 3

Say that you have an working update method in our factory class where you use AutoMapper with som ignors to translate a ModelViewObject to a ModelView(entity framework object). Say now that we updates the database table with a new field/propertie, if we run a view that handles the ModelViewObject corsponding to this tabel but do not handle the new propertie this will mean that the propertie will always be set to null/string.empty/0. When running the regular update method in the factory there will not be a ignor on this propertie and this means that the zero value will overrite the real value.

Its a big risk that these kind of updates will be done and its a big risk that I will not remember to handle this in old code.

How do I handle this?

Problem 4
AutoMapper have a validation method where you can check if the mappings will be possible, right now I am having these validations where the mapping is done, should I maby put this in some other method where the validation will be executed as fast as the application starts? Else problems in the mappings will show first when using the function.

BestRegards

  • 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-18T19:58:19+00:00Added an answer on May 18, 2026 at 7:58 pm

    At first you should use viewModel for each view. And fetch only date that you need.
    You should add facility to manual mapping for “difficult” issue.
    I thing that AutoMapper is wrong way for transfer date from Db object to View Object.

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

Sidebar

Related Questions

I am building a ASP.NET MVC application where I use the following flow :
I 'm building an application in ASP.NET MVC which should use Gmail authentication and
I am currently building an application using ASP.NET MVC. The data entry pages are
I am building an asp.net mvc web application. Do I need to use captcha
I am building an ASP.NET MVC web application using entity framework DbContext using the
I'm building an Asp.net MVC 2 application. I have an entity called Team that
I am building an ASP.Net MVC 3 application with Entity Framework 4. When the
I am building an ASP.Net MVC 3 web application using Entity Framework 4.1 with
I'm building an ASP.NET MVC application with a form that needs validation. The majority
I'm building my first ASP.NET MVC application and I am having some troubles with

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.