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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:29:13+00:00 2026-05-26T20:29:13+00:00

Here is the situation I am struggling with. I have an Object Model: public

  • 0

Here is the situation I am struggling with. I have an Object Model:

public class MyModel 
{
  public string Prop1 {get; set;}
  public string Prop2 {get; set;}
//etc
  
}

Then I have Object ModelView

public class MyModelView
{
  public MyModel MyModelObject;

  public SelectList PropToBeSelected1 {get; set;}
  public SelectList PropTobeSelected2 {get; set;}
 //etc
  
}

I have the MyModelRepository class as well that does the delete, update operations for MyModel.

All good and clear so far.

Question: PropToBeSelected1 and PropTobeSelected2 are drop down lists whose contents come from the database. Should the methods retrieving these contents be put in my MyModelRepository? Or should I create another repository for ViewModel?

  • 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-26T20:29:14+00:00Added an answer on May 26, 2026 at 8:29 pm

    First you really don’t want domian-ish objects in your viewModel. Your viewModel should be clean with only primitives (like strings, ints… etc). So I’d suggest using a AutoMapper to map your two string props to your viewModel.

    With the select list, there are many ways to go about this but I can imagine if they are lists of properties then they are not actual entities, but value objects instead. In this case creating a repository for them is over kill and boarders bad design.

    I’d put the ‘get’ of the property lists in your MyModelRepository. Something like

    _myModelRepository.getProperties1For(myModel);
    

    Then AutoMap again on to get your select list.

    Edit:
    Like @M.Radwan pointed out for complex domain models I’ll make viewModels insdie viewModels for easy of mapping.

    Domain Model–

    public class User : Entity
    {
       public Address Address { get; set; }
    }
    public class Address
    {
       public string Street {  get; set; }
       public string Zip { get; set; }
    }
    

    would map to

    public class DetailsViewModel
    {
      public int Id { get; set; }
      public string Name { get; set; }
      public AddressViewModel Address { get; set; }
      
      public class AddressViewModel
      {
        public string Street { get; set; }
        public string Zip { get; set; } 
      }
    }
    

    which in our experience has been the only reason to add any complexity to your viewModel. We will put SelectLists in our viewModel though but lately we’ve been using IEnumerables of inner viewModels and calling custom EditorFor or DisplayFor to turn them into a dropdown / list of checkboxes / radio buttons.

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

Sidebar

Related Questions

Here is the situation, I have UIViewController class with a UITableView outlet. I would
I have a question I am struggling with. Just a hypothetical situation here. For
Here is the situation. I have some ViewModels that contain nested complex model types.
I have a situation here. May I know how to get json from place
Here is situation: I have two projects. ConsoleApp and Class Library. Console app references
Lately, I'v been struggling with an annoying situation on ASP.NET MVC. Here's the story
I have a strange situation here. In my android app, I have a layout
I have a simple situation here. lets face html code first => <form name=geoKey
Here's the situation: I've got a class that is doing too much. It's mainly
Here's the situation. Due to the design of the database I have to work

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.