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
        }
    }
}
