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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:30:06+00:00 2026-05-27T19:30:06+00:00

I have a domain model: public class Project { [Key] public int ProjectID {

  • 0

I have a domain model:

public class Project
{
    [Key]
    public int ProjectID { get; set; }
    public string Title { get; set; }
    public string Slug { get; set; }
    public string Content { get; set; }
    public string Category { get; set; }
    public string Client { get; set; }
    public int Year { get; set; }
}

I have a view model (which is a portion of the above model):

public class ListProjectsViewModel
{
    public IEnumerable<ProjectStuff> SomeProjects { get; set; }

    public class ProjectStuff
    {
        public int ProjectID { get; set; }
        public string Title { get; set; }
        public string Slug { get; set; }
        public string Content { get; set; }
    }

    // Some other stuff will come here
}

I have an action controller:

    public ActionResult List()
    {
        // Get a list of projects of type IEnumerable<Project>
        var model = m_ProjectBusiness.GetProjects();

        // Prepare a view model from the above domain entity
        var viewModel = Mapper.Map..........
        return View(viewModel);
    }

How can I code the mapping ‘……..’ with automapper ?

Thanks.

  • 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-27T19:30:06+00:00Added an answer on May 27, 2026 at 7:30 pm

    There are two steps.

    1) Define a mapping with AutoMapper (this is usually done in some sort of bootstrapper called by Global.asax, etc.)

    // since all of your properties in Project match the names of the properties
    // in ProjectStuff you don't have to do anything else here
    Mapper.CreateMap<Project, ListProjectsViewModel.ProjectStuff>();
    

    2) Map the object in your controller:

    // Get a list of projects of type IEnumerable<Project>
    var projects = m_ProjectBusiness.GetProjects();
    
    // Prepare a view model from the above domain entity
    var viewModel = new ListProjectsViewModel
    {
        SomeProjects = Mapper.Map<IEnumerable<Project>, IEnumerable<ListProjectsViewModel.ProjectStuff>>(projects)
    };
    
    return View(viewModel);
    

    The thing to note here is that you are defining a mapping between Project and ProjectStuff. What you are trying to map is a list of Projects (IEnumerable) to a list of ProjectStuff (IEnumerable). AutoMapper can do this automatically by putting that in the generic arguments as I did above. Your View Model that your view is using is wrapping your list of ProjectStuff, so I just create a new ListProjectsViewModel and do the mapping inside of that.

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

Sidebar

Related Questions

Given domain model... public class Entity { public int Id { get; set; }
I have the following domain model: public class Name { private readonly string fullName;
I have an unowned relationship in my Domain model @Entity public class A {
I have the following domain model: public class Campaign { public virtual long Id
suppose I have a domain classes: public class Country { string name; IList<Region> regions;
In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
I have a class in my domain model called JobPlan this class is stored
I have a domain data model which returns a class such as the following:
I have a model that looks like this: public interface IEntity { int Id
Here is the domain that I wish to have: public class Person { public

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.