码迷,mamicode.com
首页 > 移动开发 > 详细

EF架构~对AutoMapper实体映射的扩展

时间:2016-06-25 09:33:56      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:

http://www.cnblogs.com/lori/p/3327898.html

/// <summary>
    /// AutoMapper扩展方法
    /// </summary>
    public static class AutoMapperExtension
    {
        /// <summary>
        /// 集合对集合
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="self"></param>
        /// <returns></returns>
        public static List<TResult> MapTo<TResult>(this IEnumerable self)
        {
            if (self == null)
                throw new ArgumentNullException();
            Mapper.CreateMap(self.GetType(), typeof(TResult));
            return (List<TResult>)Mapper.Map(self, self.GetType(), typeof(List<TResult>));
        }
        /// <summary>
        /// 对象对对象
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="self"></param>
        /// <returns></returns>
        public static TResult MapTo<TResult>(this object self)
        {
            if (self == null)
                throw new ArgumentNullException();
            Mapper.CreateMap(self.GetType(), typeof(TResult));
            return (TResult)Mapper.Map(self, self.GetType(), typeof(TResult));
        }

    }

 

EF架构~对AutoMapper实体映射的扩展

标签:

原文地址:http://www.cnblogs.com/shiningrise/p/5615767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!