在这种情况下,我在关注 wiki 时遇到了麻烦。我想使用 Automapper 5.2。我找不到一个简单的端到端示例来显示带有上下文的可靠配置。通过上下文我的意思是你把配置文件放在哪里,静态和实例 api 之间有什么区别?
我查看了 DNRTV 下载,但它处理的是 1.0 版本。
你如何设置这个包?我有一个名为 Client 的模型,如下所示。
public class Client : IEntityBase
{
public Client()
{
Jobs = new List<Job>();
}
public int Id { get; set; }
public int ClientNo { get; set; }
public bool Company { get; set; }
public string CompanyName { get; set; }
public string ClientFirstName { get; set; }
public DateTime DeActivated { get; set; }
public bool Activity { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateUpdated { get; set; }
public int? StateId { get; set; }
public State State { get; set; }
public int CreatorId { get; set; }
public User Creator { get; set; }
public ICollection<Job> Jobs { get; set; }
}
和一个 ClientViewModel 如下:
public class ClientViewModel
{
public int Id { get; set; }
public int ClientNo { get; set; }
public bool Company { get; set; }
public string CompanyName { get; set; }
public string ClientFirstName { get; set; }
public DateTime DeActivated { get; set; }
public bool Activity { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateUpdated { get; set; }
public int? StateId { get; set; }
public int CreatorId { get; set; }
public int[] Jobs { get; set; }
}
我不确定如何在配置方面设置 AutoMapper。也就是说,他们谈论的是 global.asax 文件,而我正在使用 aspnet core.. 没有 Global.asax 文件..
如果有的话,你在 Startup.cs 文件中放了什么。
鉴于上面的这两个文件,我需要做什么才能将 Automapper 与它们一起使用?
问候