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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:11:47+00:00 2026-06-17T08:11:47+00:00

In my solution I have two projects. Project 1 (Core) Mapping SQL to DTO

  • 0

In my solution I have two projects.

Project 1 (Core)
Mapping SQL to DTO using Dapper

Project 2 (WebUI – ASP.NET MVC 4)
Here I use a ViewModel per View.

Examples of a Controller

  [HttpGet]
    public ActionResult Edit(int id)
    {
        // Get my ProductDto in Core
        var product = Using<ProductService>().Single(id);
        var vm = new ProductFormModel(product);

        return View(vm);
    }

Examples of a ViewModel

public class ProductFormModel : BaseViewModel, ICreateProductCommand
    {
        public int ProductId { get; set; }
        public int ProductGroupId { get; set; }
        public string ArtNo { get; set; }
        public bool IsDefault { get; set; }
        public string Description { get; set; }
        public string Specification { get; set; }
        public string Unit { get; set; }
        public string Account { get; set; }
        public decimal NetPrice { get; set; }

        public ProductFormModel(int productGroupId)
        {
            this.ProductGroupId = productGroupId;
        }

        public ProductFormModel(ProductDto dto)
        {
            this.ProductId = dto.ProductId;
            this.ProductGroupId = dto.ProductGroupId;
            this.ArtNo = dto.ArtNo;
            this.IsDefault = dto.IsDefault;
            this.Description = dto.Description;
            this.Specification = dto.Specification;
            this.Unit = dto.Unit;
            this.Account = dto.Account;
            this.NetPrice = dto.NetPrice;
        }

        public ProductFormModel()
        {
        }
    }

Explanation:
I’ll get my DTOs in my controller using a service class in the project (Core).
Then i create my ViewModel and pass the DTO to the constructor in ViewModel.
I can also use this view to add a new Product because my ViewModel can take a empty constructor.

Does anyone have experience of this. I wonder if I am in this way will have problems in the future as the project gets bigger?

I know this has nothing to do with Dapper. But I would still like a good way to explain my solution.

  • 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-17T08:11:48+00:00Added an answer on June 17, 2026 at 8:11 am

    I think you will be fine using your current approach. More importantly, start out like this and refactor if you start to encounter problems related to your object mapping code (instead of thinking too much about it beforehand).

    Another way to organize mapping logic that I use sometimes is to employ extension methods. That way, the mapping code is kept separate from the view model itself. Something like:

    public static class ProductMappingExtensions
    {
        public static ProductFormModel ToViewModel(this ProductDto dto)
        {
            // Mapping code goes here
        }
    }
    
    // Usage:
    
    var viewModel = dto.ToViewModel();
    

    Yet another approach would be to use a mapping framework like AutoMapper – this is a good fit in particular if your mapping logic is simple (lots of 1:1 mappings between properties).

    But again, start simple and refactor when you need to.

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

Sidebar

Related Questions

I have two projects in my solution   1- asp.net web project.   2-
I have a Solution with several projects in it, including two asp.net mvc projects
I have two projects in the same solution. One is an ASP.NET MVC 2
I have two projects in my solution file one is Webui (a .NET application)
I have solution with two projects. ASP.NET MVC3 Class library In class library I
If for example I have a solution with two projects: Project.Core and Project.Web. Now
I have two projects in my solution, an MVC 3 (UI) project and a
I have two projects in my solution... a domain project and MVC3 web project
I have a solution with two projects. One for project for the production code
I have two C#.net projects project 1 and project 2 (names changed) in single

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.