.net core 忽略和不验证不适用于AutoMapper 8.1和.NET Core 2.1
我在.net core 忽略和不验证不适用于AutoMapper 8.1和.NET Core 2.1,.net-core,automapper,azure-functions,.net Core,Automapper,Azure Functions,我在.net core中开发了一个azure函数,并通过builder.Services.AddAutoMapper(Assembly.GetAssembly(this.GetType())在startup.cs中配置了automapper 我试图在域类(EF核心中的表)和DTO之间创建一个映射。域类具有属性RowVersion。我希望在将dto映射到域时忽略此属性 为此,我创建了一个Profile类并创建了我的自定义映射,但这不起作用 我试过不验证,但似乎不起作用 Startup.cs bui
.net core
中开发了一个azure函数,并通过builder.Services.AddAutoMapper(Assembly.GetAssembly(this.GetType())在startup.cs
中配置了automapper
代码>
我试图在域类(EF核心中的表)和DTO之间创建一个映射。域类具有属性RowVersion。我希望在将dto映射到域时忽略此属性
为此,我创建了一个Profile类并创建了我的自定义映射,但这不起作用
我试过不验证,但似乎不起作用
Startup.cs
builder.Services.AddAutoMapper(Assembly.GetAssembly(this.GetType()));
public class MapperProfile :Profile
{
public MapperProfile()
{
CreateMap<MyDto, MyDomain>().ForMember(i => i.RowVersion, opt => opt.Ignore());
}
}
_mapper.Map<myDomain>(myDtoInstance)
ForMember
用于引用目标对象,在您的示例中,MyDto
改用作为源成员
:
public MapperProfile()
{
CreateMap<MyDto, MyDomain>().ForSourceMember(i => i.RowVersion, opt => opt.Ignore());
}
publicmapperprofile()
{
CreateMap().ForSourceMember(i=>i.RowVersion,opt=>opt.Ignore());
}
public MapperProfile()
{
CreateMap<MyDto, MyDomain>().ForSourceMember(i => i.RowVersion, opt => opt.Ignore());
}