Skip to main content
deleted 5 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Using AutoMapper to map to and from. Is this kosher?

Sometimes, I need to map from a Domain entitiyentity to a ViewModel - to display information.

Other times, I need to map from a ViewModel to a Domain entity - for persistance of data.

Is this kosher or does this code smell?

protected void Application_Start() 
{
    AreaRegistration.RegisterAllAreas();
    MapObjects();
    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);
}

private void MapObjects()
{
    Mapper.CreateMap<UserModel, User>();

    Mapper.CreateMap<ProductBrandModel, ProductBrand>();
    Mapper.CreateMap<ProductBrand, ProductBrandModel>();

    Mapper.CreateMap<ProductCategoryModel, ProductCategory>();
    Mapper.CreateMap<ProductCategory, ProductCategoryModel>();
}

Using AutoMapper to map to and from. Is this kosher?

Sometimes, I need to map from a Domain entitiy to a ViewModel - to display information.

Other times, I need to map from a ViewModel to a Domain entity - for persistance of data.

Is this kosher or does this code smell?

protected void Application_Start() 
{
    AreaRegistration.RegisterAllAreas();
    MapObjects();
    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);
}

private void MapObjects()
{
    Mapper.CreateMap<UserModel, User>();

    Mapper.CreateMap<ProductBrandModel, ProductBrand>();
    Mapper.CreateMap<ProductBrand, ProductBrandModel>();

    Mapper.CreateMap<ProductCategoryModel, ProductCategory>();
    Mapper.CreateMap<ProductCategory, ProductCategoryModel>();
}

Using AutoMapper to map to and from

Sometimes, I need to map from a Domain entity to a ViewModel - to display information.

Other times, I need to map from a ViewModel to a Domain entity - for persistance of data.

Is this kosher or does this code smell?

protected void Application_Start() 
{
    AreaRegistration.RegisterAllAreas();
    MapObjects();
    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);
}

private void MapObjects()
{
    Mapper.CreateMap<UserModel, User>();

    Mapper.CreateMap<ProductBrandModel, ProductBrand>();
    Mapper.CreateMap<ProductBrand, ProductBrandModel>();

    Mapper.CreateMap<ProductCategoryModel, ProductCategory>();
    Mapper.CreateMap<ProductCategory, ProductCategoryModel>();
}
tags
Link
dfhwze
  • 13.9k
  • 3
  • 38
  • 101
Tweeted twitter.com/#!/StackCodeReview/status/106481064196849664
Source Link

Using AutoMapper to map to and from. Is this kosher?

Sometimes, I need to map from a Domain entitiy to a ViewModel - to display information.

Other times, I need to map from a ViewModel to a Domain entity - for persistance of data.

Is this kosher or does this code smell?

protected void Application_Start() 
{
    AreaRegistration.RegisterAllAreas();
    MapObjects();
    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);
}

private void MapObjects()
{
    Mapper.CreateMap<UserModel, User>();

    Mapper.CreateMap<ProductBrandModel, ProductBrand>();
    Mapper.CreateMap<ProductBrand, ProductBrandModel>();

    Mapper.CreateMap<ProductCategoryModel, ProductCategory>();
    Mapper.CreateMap<ProductCategory, ProductCategoryModel>();
}