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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.Thick.BlowingScan.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 OrgLc_AutoMapperProfile : AutoMapper.Profile
{
/// <summary>
///
/// </summary>
public static AutoMapper.IMapper Mapper;
static OrgLc_AutoMapperProfile()
{
var cfg = new AutoMapper.Configuration.MapperConfigurationExpression();
cfg.AddProfile<OrgLc_AutoMapperProfile>();
AutoMapper.MapperConfiguration config = new AutoMapper.MapperConfiguration(cfg);
Mapper = new AutoMapper.Mapper(config);
}
/// <summary>
///
/// </summary>
public OrgLc_AutoMapperProfile()
{
CreateMap<Lc_OrgScanData, Db_OrgScanData>()
.ForMember(s => s.Thicks, opt =>
{
opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.Thicks));
})
.ForMember(s => s.ThicksDt, opt =>
{
opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.ThicksDt));
})
.ReverseMap()
.ForMember(s => s.Thicks, opt =>
{
opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<double[]>(s.Thicks));
})
.ForMember(s => s.ThicksDt, opt =>
{
opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<DateTime[]>(s.ThicksDt));
});
}
}
}