LCTable.cs 1.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnitTestProject1.Model
{
    public class UserLC
    {
        public long ID { get; set; }
        public string Name { get; set; }
        public List<long> BookIDs { get; set; }
    }

    /// <summary>
    /// LC 与 DB 类的映射关系, 会在程序入口处, 手动使用 
    /// var assemblies = System.AppDomain.CurrentDomain.GetAssemblies();
    /// var cfg = new MapperConfigurationExpression();
    /// cfg.AddMaps(assemblies);
    /// Mapper.Initialize(cfg);
    /// 
    /// 枚举全部程序集 中的AutoMapper.Profile 全部加载!!!
    /// </summary>
    public class LC_AutoMapperProfile : AutoMapper.Profile
    {
        public LC_AutoMapperProfile()
        {
            #region LC_CoatingWidthData
            CreateMap<UserLC, User>()
                .ForMember(s => s.BookIDs, opt =>{
                    opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.BookIDs));
                })
                .ReverseMap()
                .ForMember(s => s.BookIDs, opt =>{
                    opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<List<long>>(s.BookIDs));
                });

            #endregion
        }
    }
}