Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I map a model to multiple tables? #12

Open
rajivkulkarni opened this issue Feb 3, 2017 · 1 comment
Open

How can I map a model to multiple tables? #12

rajivkulkarni opened this issue Feb 3, 2017 · 1 comment
Labels

Comments

@rajivkulkarni
Copy link

An example would be appreciated. The examples here are for mapping/custom mapping to a single entity. Thanks.

@MattHoneycutt
Copy link
Owner

You can do that a couple of ways:

public class MyModel : IMapFrom<Entity1>, IMapFrom<Entity2>
{

}

Or, you can do it by implementing IHaveCustomMappings:

public class MyModel : IHaveCustomMappings
{
   public void CreateMappings(IMapperConfigurationExpression configuration)
   {
       configuration.CreateMap<Entity1, MyModel>()
           .ForMember(x => x.Name, opt => opt.MapFrom(x => x.FullName));

       configuration.CreateMap<Entity2, MyModel>()
           .ForMember(x => x.Name, opt => opt.MapFrom(x => x.FullName));
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants