C# 简单映射在我的自动映射配置中不起作用
我正在尝试使用此映射方法进行简单映射:C# 简单映射在我的自动映射配置中不起作用,c#,automapper,C#,Automapper,我正在尝试使用此映射方法进行简单映射: CreateMap<MgalaxyGroup, MgalaxyGroupDto>() .ForMember(d => d.Differentiator, opt => opt.MapFrom(MgalaxyGroup.Differentiator)); 但我正在MgalaxyGroup类中定义字符串微分器: public sealed class MgalaxyGroup { ....
CreateMap<MgalaxyGroup, MgalaxyGroupDto>()
.ForMember(d => d.Differentiator, opt => opt.MapFrom(MgalaxyGroup.Differentiator));
但我正在MgalaxyGroup类中定义字符串微分器
:
public sealed class MgalaxyGroup
{
....
// it's defined right here
public const String Differentiator = "primaryStars";
这里是dto
public class MgalaxyGroupDto
{
public Int32? Id { get; set; }
public String TypeId{ get; set; }
// it's here
public String Differentiator { get; set; }
}
那么为什么它会说ArgumentOutOfRangeException
?现在我不太确定该怎么办
谢谢 为什么一个是常量,另一个是可编辑属性?映射时,AutoMapper可能会排除
const
?除非您得到更好的建议,否则可以将其更改为publicstringdifferentiator{get;}=“primaryStars”代码>@gunr2171老实说我不知道。自从我接手这个大学项目以来,一直都是这样。我们最近升级了Automapper,遇到了这个问题。我可以尝试将其更改为与dto匹配,以查看是否修复了它。谢谢如果可以的话,您可以完全放弃AutoMapper:这可能需要是opt=>opt.MapFrom(m=>m.differentior)
。您正在映射到类型本身,而不是该类型的实例属性。
public class MgalaxyGroupDto
{
public Int32? Id { get; set; }
public String TypeId{ get; set; }
// it's here
public String Differentiator { get; set; }
}