基于映射字典的源模型到目标模型的映射

时间:2018-08-23 21:53:45

标签: c# .net model .net-core

这是交易 我有一个源模型和目标模型

public class SourceModel
{
    public long Id { get; set; }
    public string FileRegion { get; set; }
    public string FileName { get; set; }
    public string OpCode { get; set; }
    public string RecordType { get; set; }
    public string SomeField1 { get; set; }
    public string SomeField2 { get; set; }
    public string SomeField3 { get; set; }
}

public class TargetModel
{
    public long TargetId { get; set; }
    public string TargetRegion { get; set; }
    public string TargetRec { get; set; }
    public string TargetRec1 { get; set; }
    public string TargetRec2 { get; set; }
}

我想基于xml中的映射信息将某些源映射到目标字段中

<mappings>
  <column target= id source = id/>
  <column target= targetregion source = region/>
  <column target= targetrec source = recordtype/>
  <column target= targetrec1 source= somefield1/>
  <column target= targetrec2 source= somefield3/>
</mappings>

我想基于映射返回目标模型。

我可以通过编程方式分别映射它们,并使其返回目标模型,但是我想知道是否可以通过给定的XML映射信息来完成

0 个答案:

没有答案
相关问题