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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:18:06+00:00 2026-06-02T23:18:06+00:00

I have built a simple survey-tool using MVC 3 with only 1 layer (MVC).

  • 0

I have built a simple survey-tool using MVC 3 with only 1 layer (MVC). I regret this now. All my database access and mapping is handled in the controllers, and some other mapping classes.

I would like to switch over to using three layers:

Presentation (MVC)
Business Logic
Data / Persistence (EF)

I am using the Entity Framework to handle everything with the database. The entity framework creates it’s own domain classes. Where should the mapping between the Models that MVC uses and the models that EF creates go?

If the mapping is in the business layer, is there a need for the Models folder in the MVC project?

A survey-question consists of the Question itself, Rows and Columns. Theese are the models that i use:

public class Question {

        public int Question_ID { get; set; }

        public Boolean Condition_Fullfilled;

        [Required(ErrorMessage = "Dette felt er påkrævet")]
        public String Question_Wording { get; set; }

        public String Question_Type { get; set; }

        [Required(ErrorMessage = "Dette felt er påkrævet")]
        public String Question_Order { get; set; }

        public String Left_scale { get; set; }
        public String Right_scale { get; set; }
        public int Scale_Length { get; set; }
        public String Left_Scale_HelpText { get; set; }
        public String Right_Scale_HelpText { get; set; }

        public Boolean Visible { get; set; }
        public Boolean IsAnswered { get; set; }
        public String Question_HelpText { get; set; }
        public int Category_ID { get; set; }

}
public class MatrixColumns
    {
        public int Column_ID { get; set; }
        public int Column_Number { get; set; }
        public String Column_Description { get; set; }
        public Boolean IsAnswer { get; set; }
        public int? Procent { get; set; }
        public bool Delete { get; set; }
        public bool Visible { get; set; }
        public int? Numbers { get; set; }
        public String Help_Text { get; set; }

    }

    public class MatrixRows
    {
        public bool Delete { get; set; }
        public bool Visible { get; set; }
        public int Row_Id { get; set; }
        public String Row_Number { get; set; }
        public String Row_Description { get; set; }
        public String Special_Row_CSS { get; set; }
        public String Help_Text { get; set; }
        // Dette er summen af procenterne af alle kolonner i rækken
        public int RowSum { get; set; }
    }

All the data for theese models is retrieved in the Controller, based upon a QuestionID, and mapped to a ViewModel that looks like this:

 public class ShowMatrixQuestionViewModel : Question
    {
        public Dictionary<MatrixRows, List<MatrixColumns>> columnrow { get; set; }
        public List<MatrixColumns> columns { get; set; }
        public List<MatrixRows> rows { get; set; }

        public ShowMatrixQuestionViewModel()
        {
            columns = new List<MatrixColumns>();
            rows = new List<MatrixRows>();
            columnrow = new Dictionary<MatrixRows, List<MatrixColumns>>();
        }
    }

So when i want to send a ShowMatrixQuestionViewModel to a View from my Controller, what is the route i should take?

This is my suggestion:

-> Controller calls a method in the business layer called

public ShowMatrixViewModel GetQuestion(int QuestionID) {}

-> GetQuestion calls the following methods in the data layer:

public Question GetQuestion(int QuestionId) {}
public MatrixRows GetRows(int QuestionId) {}
public MatrixColumns GetColumns(int id) {}

-> Entity framework returns “pure” objects, which i want to map over to the ones i posted above
-> GetQuestion calls methods to map the EF models to my own models
-> Last GetQuestion calls a method that maps the Questions, Rows and Columns:

    ShowMatrixQuestionViewModel model = MapShowMatrixQuestionViewModel(Question, MatrixRows, MatrixColumns)
return model;

Is this correct?

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-06-02T23:18:08+00:00Added an answer on June 2, 2026 at 11:18 pm

    To answer the first part of your question:

    “Where should the mapping between the Models that MVC uses and the models that EF creates go?”

    The answer is that the models MVC uses are the models created by the EF. Your EF tool in the ASP.NET MVC project is either Linq to SQL Classes or the ADO.NET Entity Framework Model. You should create these inside the Models folder in your project and they provide your data / persistence (EF).

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

Sidebar

Related Questions

I have built a simple database posted here (Access 2007 format): http://www.derekbeck.com/Database1.accdb I have
I have built a simple transport agent (using .NET 4.0) for exchange 2010 and
I have built a simple C#.Net app on a M/C with only .Net FX
I have built a very simple blog application using Ruby on Rails. New to
Does Python have a built-in, simple way of encoding/decoding strings using a password? Something
I have a cakePhp application built, and now I'm creating a simple blog based
I have built a simple website monitoring application using Indy TIdhttp component. I want
I have built a variety of little scripts using Ruby's very simple Queue class,
I have built a simple static website using media queries to resize for tablets
all. I have built a simple jQuery/PHP chat program that works rather well. However,

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.