automapper

Automapper not ignoring nested property

吃可爱长大的小学妹 提交于 2019-12-07 12:29:57
问题 I've had a look through the various similar posts but can't spot the error of my ways with this one. Basically I have two views which update different parts of a "Settings" object. The view models contain one of two properties and depending on which is being set, should ignore the other. It works fine when it's ViewModel ==> Entity direct but when Automapper tries to update the nested object it fails. I have the following object structure: public class Account { public int AccountId { get;

Updated AutoMapper and now receiving unmapped property exception

跟風遠走 提交于 2019-12-07 12:08:27
问题 I have the following mapping: Mapper.CreateMap<Playlist, PlaylistDto>() .ReverseMap() .ForMember(playlist => playlist.Folder, opt => opt.MapFrom(playlistDto => folderDao.Get(playlistDto.FolderId))); Which converts a Playlist object to a PlaylistDto object and back. It seemed to work great before I updated AutoMapper. Now, when I call: Mapper.AssertConfigurationIsValid(); I see: Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a

AutoMapper : Map both ways in Net Core 2 syntax

不羁的心 提交于 2019-12-07 10:38:27
What is syntax to map both ways in AutoMapper Net Core2? I need to map ProductViewModel and ProductDto both ways. This is not working, Startup.cs var config = new MapperConfiguration ( cfg => cfg.CreateMap<Models.ProductDto, Models.ProductViewModel>(), cfg => cfg.CreateMap<Models.ProductViewModel, Models.ProductDto>() ); var mapper = config.CreateMapper(); I'd rather create a seprate initializer and mapper. e.g here is my AutoMapperStartupTask class. public static class AutoMapperStartupTask { public static void Execute() { Mapper.Initialize( cfg => { cfg.CreateMap<ProductViewModel, ProductDto

Polymorphic Mapping of Collections with AutoMapper

那年仲夏 提交于 2019-12-07 10:33:38
问题 TL;DR: I'm having trouble with Polymorphic mapping. I've made a github repo with a test suite that illustrates my issue. Please find it here: LINK TO REPO I'm working on implementing a save/load feature. To accomplish this, I need to make sure the domain model that I'm serializing is represented in a serialization-friendly way. To accomplish this I've created a set of DTOs that contain the bare-minimum set of information required to do a meaningful save or load. Something like this for the

Automapper enum to Enumeration Class

半腔热情 提交于 2019-12-07 09:18:20
问题 I'm trying to use Automapper to map from a regular enum to an Enumeration Class (as described by Jimmy Bogard - http://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/). The regular enum doesn't have the same values as the enumeration class does. I would therefore like to map using the Name if possible: Enum: public enum ProductType { ProductType1, ProductType2 } Enumeration Class: public class ProductType : Enumeration { public static ProductType ProductType1 = new ProductType(8,

How to ignore a property based on a runtime condition?

落花浮王杯 提交于 2019-12-07 09:01:24
问题 I have a simple pair of classes which for I've set up a mapping at initialization time. public class Order { public int ID { get; set; } public string Foo { get; set; } } public class OrderDTO { public int ID { get; set; } public string Foo { get; set; } } ... Mapper.CreateMap<Order, OrderDTO>(); Now at a certain point I need to map an Order to an OrderDTO . BUT depending on some circumstances, I might need to ignore Foo during mapping. Let's also assume that I cannot "store" the condition in

AutoMapper with Ninject

廉价感情. 提交于 2019-12-07 08:47:32
问题 I've been trying to setup AutoMapper to instantiate all objects via Ninject. I've got the following code in my global.asax file Mapper.Configuration.ConstructServicesUsing(x => kernel.Get(x)); And as an example I have the following mapping Mapper.CreateMap<TestModel, IndexViewModel>(); However, this does not appear to be working. I get an error that 'IndexViewModel' does not have a default constructor. I can get the mapper to work by explicitly telling automapper to use ninject in the mapping

Cannot resolve AutoMapper.IMapper using AutoMapper 4.2 with Autofac

感情迁移 提交于 2019-12-07 08:07:35
问题 I have tried various permutations of this but my current configuration (as it relates to AutoMapper) is like this: builder.RegisterAssemblyTypes().AssignableTo(typeof(Profile)).As<Profile>(); builder.Register(c => new MapperConfiguration(cfg => { foreach (var profile in c.Resolve<IEnumerable<Profile>>()) { cfg.AddProfile(profile); } })).AsSelf().SingleInstance(); builder.Register(c => c.Resolve<MapperConfiguration>().CreateMapper(c.Resolve)).As<IMapper>().InstancePerLifetimeScope(); builder

How to resolve AutoMapper error? (stackoverflow exception!)

女生的网名这么多〃 提交于 2019-12-07 05:10:52
问题 I am using AutoMapper + EF (Entities => POCO) for the following class: public class Category { public int CategoryID { get; set; } public string Name { get; set; } public Category Parent { get; set; } public IList<Category> Children { get; set; } } Since this class has relationship with itself (Parent / Children), AutoMapper went crazy and threw a Stackoverflow exception. Have ever any of you experienced this problem? 回答1: I've resolved it by creating CustomValueResolvers. It is not the

AutoMapper: Map Interface to Abstract class - is this possible?

梦想与她 提交于 2019-12-07 05:09:40
问题 I'm using AutoMapper to map objects between different layers of my application. On the one side I have an interface which looks like this: public interface MyRepo { IEnumerable<IRootObject> GetItems(param); } IRootObject looks like this: public interface IRootObject { int Id { get; set; } DateTime? Date { get; set; } } public interface IFirstSubObject : IRootObject { string MyFirstProp { get; set; } } public interface ISecondSubObject : IRootObject { string MySecondProp { get; set; } } So the