[英]Automapper with dynamic values C#
我有點卡住了,希望得到指導。 我有 2 張桌子,Header 和詳細信息。 然而,細節與大多數不同,並允許一種動態存儲數據的方式。:是的,我知道我可以創建一個以標准方式存儲細節的表,但應用程序的性質需要在數據庫方面更加動態。 我也意識到我必須為應用程序的不同化身修改 DTO,但是這個 model 是我需要完成的。
public class Header
{
public int Id { get; set; }
public string HeaderName { get; set; }
public ICollection<Detail> Details { get; set; }
}
public class Detail
{
public int Id { get; set; }
public int HeaderId { get; set; }
public string FieldName { get; set; }
public string FieldProperty { get; set; }
}
我想使用以下 DTO:
public class DataForDisplayDto
{
public int Id { get; set; }
public string HeaderName { get; set; }
public string TaskToPerform { get; set; }
public string Location { get; set; }
}
public class DataForCreationDto
{
public string HeaderName { get; set; }
public string TaskToPerform { get; set; }
public string Location { get; set; }
}
數據將以這種方式存儲在詳細信息中:
{
"FieldName": "tasktoperform",
"FieldProperty": "Thing to Do"
},
{
"FieldName": "location",
"FieldProperty": "Over there"
}
我正在嘗試使用 Automapper 來制作它,以便我可以使用 DTO 讀取和寫入數據庫,但我想我可能正在嘗試它無法做到的事情。
是否有任何人知道的文章或內容可以將我指向 go 的方向? 甚至是正確的關鍵字在線搜索它。 甚至可能嗎?
我想如果不可能,我將不得不手動做更多的事情,這是最后一個選擇,我只是希望用 Automapper 來做這件事。
謝謝!
如何從使用反射生成映射並緩存該映射的基礎 class 派生 DTO。
這樣你的 DTO 只需要繼承一個基礎 class。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.