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 BookIDs { get; set; } } /// /// LC 与 DB 类的映射关系, 会在程序入口处, 手动使用 /// var assemblies = System.AppDomain.CurrentDomain.GetAssemblies(); /// var cfg = new MapperConfigurationExpression(); /// cfg.AddMaps(assemblies); /// Mapper.Initialize(cfg); /// /// 枚举全部程序集 中的AutoMapper.Profile 全部加载!!! /// public class LC_AutoMapperProfile : AutoMapper.Profile { public LC_AutoMapperProfile() { #region LC_CoatingWidthData CreateMap() .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>(s.BookIDs)); }); #endregion } } }