我想將Dapper數據映射到對象。但在映射到Dictionary對象時遇到問題。Slapper&Dapper字典支持
要求是將數據行映射到對象。
數據行
1 | Key1 | Value1
1 | Key2 |值2
期望值
標識 - >1
數據 - {{"Key1","Value1" }, { "Key2","Value2"}}
地圖代碼:
IDictionary<string, object> entity = new Dictionary<string, object>();
entity.Add("Id", "1");
entity.Add("Data_Key", new List<string>() { "Key1", "Key2" });
entity.Add("Data_Value", new List<string>() { "Value1", "Value2" });
var result=Slapper.AutoMapper.Map<TestEntity>(entity);
實體Ø bject
public class TestEntity
{
public int Id { get; set; }
public Dictionary<string,string> Data { get; set; }
}
有沒有辦法實現這個?
是的..我無法通過直接映射來實現它。所以,我必須做一個解決方法(發佈)。 感謝您的幫助。 –