博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AutoMapper使用中的问题
阅读量:4589 次
发布时间:2019-06-09

本文共 1223 字,大约阅读时间需要 4 分钟。

指定值只会执行一次

 

public class MomanBaseProfile : Profile    {        public MomanBaseProfile()        {            CreateMap
() .ForMember(d => d.ID, op => op.Ignore()) .ForMember(d => d.UID, op => op.UseValue(Guid.NewGuid()))//使用Mapper过程中始终不变 .ForMember(d => d.CreateTime, op => op.UseValue(DateTime.UtcNow)) .ForMember(d => d.UpdateTime, op => op.UseValue(DateTime.UtcNow)); CreateMap
() .IncludeBase
(); } }

 

继承类如何减少Map问题解决

 
public class MomanBaseProfile : Profile    {        public MomanBaseProfile()        {            CreateMap
() .ForMember(d => d.ID, op => op.Ignore()) .ForMember(d => d.UID, x => x.MapFrom(ax => Guid.NewGuid())) .ForMember(d => d.CreateTime, x => x.MapFrom(ax => DateTime.UtcNow)) .ForMember(d => d.UpdateTime, x => x.MapFrom(ax => DateTime.UtcNow)); //继承类两种方式,一种使用IncludeBase(从父类映射继承)如下,另一中使用Include(从子类映射继承) CreateMap
() .IncludeBase
(); } }
 

参考

转载于:https://www.cnblogs.com/HQFZ/p/5909550.html

你可能感兴趣的文章
电脑公司GHOST WIN7 装机旗舰版 2013 09
查看>>
ubuntu安装搜狗输入法
查看>>
sql查询优化相关
查看>>
减少选择让你节省时间
查看>>
windows和linux出现timewait过多的解决方法
查看>>
Java基础学习--抽象类与抽象函数
查看>>
C#如何读取Excel
查看>>
CIO访谈实录丨渤海人寿携手SmartX超融合大幅提升开发测试效率
查看>>
小学运算
查看>>
Redis(数据库)学习
查看>>
MiniGUI - 位图
查看>>
STM32 F4 GPIO Modes
查看>>
6、scala面向对象-对象
查看>>
好的软件架构设计(转)
查看>>
程序员的感叹(中国版_Made In China)
查看>>
获取按钮回发函数
查看>>
精神哥讲Crash(一):UnsatisfiedLinkError
查看>>
SSH配置—Linux下实现免密码登录
查看>>
Django之--模板加载图片
查看>>
Selenium WebDriver + Grid2 + RSpec之旅(二)----Grid2的配置
查看>>