映射嵌套的类模型

时间:2017-11-23 06:49:42

标签: c# .net

从Web API调用中,我收到了响应并将其存储在此模型中

public class DetailedTogglResponse
{
    public List<TogglDetailedReport> data { get; set; }
    public string total_grand { get; set; }
    public string total_billable { get; set; }
}

以下是该模型的代码:

public class TogglDetailedReport
{
    public int id { get; set; }
    public int pid { get; set; }
    public int? tid { get; set; }
    public int uid { get; set; }
    public String description { get; set; }
    public DateTime start { get; set; }
    public DateTime end { get; set; }
    public int dur { get; set; }
    public String client { get; set; }
    public Decimal billable { get; set; }
    public bool is_billable { get; set; }
    public String cur { get; set; }
    public List<String> tags { get; set; }
}

public class Tags
{
    public String TagName { get; set; }
}

现在,我希望使用TogglDetailedReportDetailedReport进行“自动映射”(仅部分代码,不显示List<Tags> tags { get; set; }

如何“自动映射”TogglDetailedReport到DetailedReport?

public class DetailedReport
{
    public int TimeEntryId { get; set; } // TimeEntryId (Primary key)
    public int ProjectId { get; set; } // ProjectId
    public int? TaskId { get; set; } // TaskId
    public int UserId { get; set; } // UserId
    public string Description { get; set; } // Description (length: 250)
    public string ClientName { get; set; } // ClientName (length: 50)
    public System.DateTime StartTime { get; set; } // StartTime
    public System.DateTime EndTime { get; set; } // EndTime
    public int Duration { get; set; } // Duration
    public decimal Billable { get; set; } // Billable
    public bool IsBillable { get; set; } // IsBillable
    public string Currency { get; set; } // Currency (length: 10)
    public System.DateTime CreatedDate { get; set; } // CreatedDate
}

0 个答案:

没有答案