automapper-6

AutoMapper - map to derived objects depend on condition

泄露秘密 提交于 2019-12-11 10:58:46
问题 I want to map source class to derived (from abstract) destination classes depend on value of some property. I have the following source classes: public partial class ApplicationDriver { public virtual ICollection<ApplicationDriverEquipment> Equipments { get; set; } } public partial class ApplicationDriverEquipment { public int Id { get; set; } [StringLength(256)] public string Make { get; set; } [StringLength(256)] public string Model { get; set; } [StringLength(256)] public string Year { get

Integration Testing with AutoMapper fails to initialise configuration

狂风中的少年 提交于 2019-12-11 02:21:06
问题 Frameworks & Packages .NETCoreApp 1.1 Xunit 2.2.0 AutoMapper 6.0.2 Microsoft.AspNetCore.TestHost 1.1.1 Microsoft.NET.Test.Sdk 15.0.0 Integration Test public class ControllerRequestsShould { private readonly TestServer _server; private readonly HttpClient _client; public ControllerRequestsShould() { _server = new TestServer(new WebHostBuilder() .UseContentRoot(Constants.apiProjectRoot) .UseStartup<Startup>() .UseEnvironment(Constants.testingEnvironment)); _client = _server.CreateClient();

AutoMapper: What is the difference between ForMember() and ForPath()?

雨燕双飞 提交于 2019-12-08 17:07:39
问题 I am reading AutoMapper's ReverseMap() and I can not understand the difference between ForMember() and ForPath() . Implementations was described here. In my experience I achieved with ForMember() . See the following code where I have configured reverse mapping: public class Customer { public string Surname { get; set; } public string Name { get; set; } public int Age { get; set; } } public class CustomerDto { public string CustomerName { get; set; } public int Age { get; set; } } static void

Automapper - Mapper already initialized error

落爺英雄遲暮 提交于 2019-11-29 09:05:12
I am using AutoMapper 6.2.0 in my ASP.NET MVC 5 application. When I call my view through controller it shows all things right. But, when I refresh that view, Visual Studio shows an error: System.InvalidOperationException: 'Mapper already initialized. You must call Initialize once per application domain/process.' I am using AutoMapper only in one controller. Not made any configuration in any place yet nor used AutoMapper in any other service or controller. My controller: public class StudentsController : Controller { private DataContext db = new DataContext(); // GET: Students public