Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 自动映射忽略嵌套属性_C#_Properties_Automapper_Ignore - Fatal编程技术网

C# 自动映射忽略嵌套属性

C# 自动映射忽略嵌套属性,c#,properties,automapper,ignore,C#,Properties,Automapper,Ignore,我试图忽略InProductionRWDto类中的嵌套属性 public class InProductionRWDto { public int InProductionRWId { get; set; } public int InProductionId { get; set; } public InProductionDto InProduction { get; set; } public WareDto Ware { get; set; } p

我试图忽略InProductionRWDto类中的嵌套属性

public class InProductionRWDto
{
    public int InProductionRWId { get; set; }
    public int InProductionId { get; set; }
    public InProductionDto InProduction { get; set; }
    public WareDto Ware { get; set; }
    public int? WareQuantity { get; set; }
    public decimal? WareLength { get; set; }
    public string WareUnit { get; set; }
    public int ToIssue { get; set; } = 1;
    public int ToIssuePerBook { get; set; } = 1;
    public int ToIssuePerSubOrder { get; set; } = 1;
    public int PlannedToCut { get; set; }
    public int Issued { get; set; }
    public int TotalToIssue { get; set; }
    public decimal? QtyWhDiff { get; set; }
    public sbyte ProductionStateCode { get; set; }
}
但当我这么做的时候:

CreateMap<InProductionRW, InProductionRWDto>()
            .ForPath(dest => dest.InProduction.ParentReservation, opt => opt.Ignore());
CreateMap()
.ForPath(dest=>dest.InProduction.ParentReservation,opt=>opt.Ignore());
Automapper正在忽略整个生产属性

更新

生产中的映射

CreateMap<InProduction, InProductionDto>();
CreateMap<InProductionDto, InProduction>();
CreateMap();
CreateMap();

有人能帮我做这个吗?

!PropInfo.DeclaringType.Name.Equals(PropInfo.PropertyType.Name)

我通过从所有DTO中删除导航属性解决了这个问题。它们导致循环引用,最终导致StackOverFlow异常。

什么对象映射到
InProduction
属性?这两个对象之间应该有一个
CreateMap
,这就是我通常放置ignore的位置。是的,我正在映射InProduction属性-请参阅更新的问题。但当我在InProduction映射中忽略ParentReservation时,AutoMapper会引发StackOverflow异常。因此,看起来您要从InProduction转到InProductionDto,所以请使用您的第一个示例并将忽略添加到该示例中<代码>CreateMap().FormMember(source=>source.ParentReservation,x=>x.Ignore()如果有效,我会回答。它不起作用。我收到StackOverflowException:AutoMapper.dll中发生了类型为“System.StackOverflowException”的未处理异常,您使用的是哪个版本的C#和AutoMapper?也许您使用的是旧版本的AM。我看不出在新版本中可能发生这种情况。请参阅。