Mapping business Objects and Entity Object with reflection c#

前端 未结 3 1924
一生所求
一生所求 2020-12-20 02:03

I want to somehow map entity object to business object using reflection in c# -

public class Category
    {
        public int CategoryID { get; set; }
            


        
3条回答
  •  被撕碎了的回忆
    2020-12-20 02:24

    http://automapper.codeplex.com/

    My vote is for auto mapper. I currently use this. I've done performance tests on it, and although it is not as fast as hand mapping (below):

    Category c = new Category 
      {
        id = entity.id,
        name = entity.name
      };
    

    The trade off for mapping automatically makes it an obvious choice, at least for the entity to business layer mapping. I actually hand map from the business layer to the view model because I need the flexibility.

提交回复
热议问题