using FLY.Thick.Blowing.IService; using FLY.Weight.Common; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FLY.Weight.Server.Model { /// <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 { /// <summary> /// /// </summary> public static AutoMapper.IMapper Mapper; static Lc_AutoMapperProfile() { var cfg = new AutoMapper.Configuration.MapperConfigurationExpression(); cfg.AddProfile<Lc_AutoMapperProfile>(); AutoMapper.MapperConfiguration config = new AutoMapper.MapperConfiguration(cfg); Mapper = new AutoMapper.Mapper(config); } /// <summary> /// /// </summary> public Lc_AutoMapperProfile() { CreateMap<Lc_Flow, Db_Flow>() .ForMember(s => s.Items, opt => { opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.Items)); }) .ReverseMap() .ForMember(s => s.Items, opt => { opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<List<FlyData_FlowItem>>(s.Items)); }); CreateMap<Lc_Mix, Db_Mix>() .ForMember(s => s.Items, opt => { opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.Items)); }) .ReverseMap() .ForMember(s => s.Items, opt => { opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<List<FlyData_MixItem>>(s.Items)); }); CreateMap<Lc_Mix, Db_RollMix>() .ForMember(s => s.Items, opt => { opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.Items)); }) .ReverseMap() .ForMember(s => s.Items, opt => { opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<List<FlyData_MixItem>>(s.Items)); }); } } }