我在使用Automapper Projections的應用程序中處理自引用模型時遇到問題。這是我的模型如何:Automapper自引用模型投影
public class Letter
{
public int? ParentId {get; set;}
public Letter ParentLetter {get; set;
public int Id {get; set;}
public string Title {get; set;}
public string Content {get; set;}
public DateTime? ReceivedTime {get; set;}
public DateTime? SendingTime {get; set;}
public List<Destination> Destinations {get; set;}
public List<Letter> Responses {get; set;}
}
public class LetterView
{
public int? ParentId {get; set;}
public int Id {get; set;}
public string Title {get; set;}
public string Content {get; set;}
public DateTime? ReceivedTime {get; set;}
public DateTime? SendingTime {get; set;}
public List<DestinationView> Destinations {get; set;}
public List<LetterView> Responses {get; set;}
}
public class Destination
{
public int Id {get; set;}
public string Name {get; set;}
..
}
public class DestinationView
{
public int Id {get; set;}
public string Name {get; set;}
}
// The mapping:
CreateMap<Destination, DestinationView>
CreateMap<Letter, LetterView>
我的問題是與信件映射到LetterView。問題出在答覆處,我無法弄清楚應該改變什麼。
無論何時運行單元測試和斷言映射配置一切正常,以及映射帶有對視圖模型的多個響應的字母。然而,每當我從數據庫(實體框架6)得到一個帶有resposnes的字母時,對LetterView的投影就拋出一個stackoverflow異常。
任何人都可以請解釋爲什麼這隻發生在投影?我應該改變什麼?
您是否有堆棧溢出的堆棧跟蹤? –