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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:33:05+00:00 2026-06-04T02:33:05+00:00

How to map User class to UserModel class using Emit Mapper? public class User

  • 0

How to map User class to UserModel class using Emit Mapper?

    public class User
    {
        public Guid Id { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public IList<Role> Roles { get; set; }

        public Company Company { get; set; }        
    }

    public class UserModel
    {
        public Guid Id { get; set; }

        public Guid CompanyId { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }      

        public IList<RoleModel> Roles { get; set; }
}

There several problems:

  • I need to flatten the object such that I will have CompanyId instead of the Company object.
  • Company object has property Id, in the UserModel I have CompanyId which corresponds to the company id, but property names do not match.
  • I need to map List<Role> to List<RoleModel>
  • 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-04T02:33:07+00:00Added an answer on June 4, 2026 at 2:33 am
    • For flattering I was using configuration from the samples in Emit Mapper source files: http://emitmapper.codeplex.com/SourceControl/changeset/view/69894#1192663

    • To make the names to match in Company class should be the field with the name Id

    • For mapping List<Role> to List<RoleModel> I was using custom converter:

      public class EntityListToModelListConverter<TEntity, TModel>
      {
          public List<TModel> Convert(IList<TEntity> from, object state)
          {
              if (from == null)
                  return null;
      
              var models = new List<TModel>();
              var mapper = ObjectMapperManager.DefaultInstance.GetMapper<TEntity, TModel>();
      
              for (int i = 0; i < from.Count(); i++)
              {
                  models.Add(mapper.Map(from.ElementAt(i)));
              }
      
              return models;
          }
      }
      

      So all together:

       var userMapper = ObjectMapperManager.DefaultInstance.GetMapper<User, UserModel>( 
                   new FlatteringConfig().ConvertGeneric(typeof(IList<>), typeof(IList<>), 
                   new DefaultCustomConverterProvider(typeof(EntityListToModelListConverter<,>))));
      
    • There is a problem, using Flatterning Configuration with Custom converters, check my question: Emit Mapper Flattering with Custom Converters

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

Sidebar

Related Questions

I have a class like public User class { public string Name{get;set;} public string
Using NHibernate, how can I map the following scenario: public class User { public
How do I get the fields in User to map to LookUpDetail using EF
Object Class: class User{ public String name; public String password; } JSON: { sc:200,
I have a user object like so: public class User { public Guid UserId
My User table I want to map to aspnet_Users: <class name=User table=`User`> <id name=ID
Is it possible to map an ActiveRecord class using the MetadataType attribute in order
I have the following entities: public class User { public virtual ICollection<Role> Roles {
I have an User entity: @Entity @Table(name = user) public class User implements Serializable{
My application has the following entities: public class User { public virtual int UserID

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.