automapper

Automapper Formatter not working

狂风中的少年 提交于 2019-12-11 02:47:48
问题 I'm trying to add a formatter to my Automapper configuration to style all DateTime? fields. I've tried adding my formatter globally: Mapper.AddFormatter<DateStringFormatter>(); And on the specific mapping itself: Mapper.CreateMap<Post, PostViewModel>() .ForMember(dto => dto.Published, opt => opt.AddFormatter<DateStringFormatter>()); But neither seems to work - it always outputs the date in the normal format. For reference, here is the ViewModel I'm using, and the rest of the configuration:

AutoMapper Object Collections not mapping

时光怂恿深爱的人放手 提交于 2019-12-11 02:26:19
问题 I am trying to map a class which has an identical layout to the class I am trying to map to. All goes well except when I try to map Object collections. For example when I try to map this property defined in the source class: [System.Xml.Serialization.XmlElementAttribute("trust", typeof(Trust))] [System.Xml.Serialization.XmlElementAttribute("valuation", typeof(Valuation))] [System.Xml.Serialization.XmlElementAttribute("waiver_of_premium_ind", typeof(YesNo))] [System.Xml.Serialization

Automapper Enum Description Attribute

时光怂恿深爱的人放手 提交于 2019-12-11 02:13:16
问题 I'm having difficulties mapping from an Enum Description Attribute. I've been looking all over for a useful example with very little luck. I know there are some other examples out there but I'm still struggling with this particular scenario. Here is my Enum: public enum ResolveCodeEnum { [Description("Resolved - Workaround")] ResolvedWorkaround = 1, [Description("Resolved - Permanently")] ResolvedPermanently = 2, [Description("Resolved - Unknown")] ResolvedUnkown = 3, [Description("Cannot

IoC with AutoMapper Profile using Autofac

你离开我真会死。 提交于 2019-12-11 01:49:56
问题 I have been using AutoMapper for some time now. I have a profile setup like so: public class ViewModelAutoMapperConfiguration : Profile { protected override string ProfileName { get { return "ViewModel"; } } protected override void Configure() { AddFormatter<HtmlEncoderFormatter>(); CreateMap<IUser, UserViewModel>(); } } I add this to the mapper using the following call: Mapper.Initialize(x => x.AddProfile<ViewModelAutoMapperConfiguration>()); However, I now want to pass a dependency into the

Asp.net core 2.0 AutoMapper IValueResolver dependency injection

天大地大妈咪最大 提交于 2019-12-11 01:39:01
问题 I have tried most of the examples in the Google Results, Stackoverflow and in AutoMapper. But was not able to get the IValueResolverdependancy injection to work. I have below service public class StorageService : IStorageService { private readonly BlobServiceSettings _blobServiceSettings; public StorageService(IOptions<BlobServiceSettings> blobServiceSettings) { _blobServiceSettings = blobServiceSettings.Value; } // some methods I need } This is my profile public class MappingProfile :

“Missing type map configuration or unsupported mapping” after deploying

天涯浪子 提交于 2019-12-11 00:45:48
问题 Each time after I deploy my code into IIS I keep getting the error "Missing type map configuration or unsupported mapping". Once I restart IIS, the problem goes away, so I don't think it's my code. However, today, I am continuing to get this error. The mapping error initially happened in one place and after restarting, it is now happening on different mappings, so it's not always the same place. Is there anything with a release into IIS that would cause Automapper to use a previously "cached"

Automapper: How to get source property name from PropertyMap

China☆狼群 提交于 2019-12-11 00:37:48
问题 How do I get the name of the source property from the property map in this code: IEnumerable<PropertyMap> propertyMapList = Mapper.FindTypeMapFor<TFrom, TTo>().GetPropertyMaps(); foreach (PropertyMap propertyMap in propertyMapList) { ////..... } 回答1: This should work in AutoMapper v1 (haven't tried in v2 yet). foreach (PropertyMap propertyMap in propertyMapList) { var resolver = propertyMap.GetSourceValueResolvers().First(); var getter = (IMemberGetter) resolver; var info = getter.MemberInfo;

Automapper says Missing map from System.String to System.Char? But I see no Char property

若如初见. 提交于 2019-12-10 23:55:21
问题 I've got three classes: public class UserReport : Entity { public string Name { get; set; } public string Email { get; set; } public List<string> Departments { get; set; } public List<string> Titles { get; set; } } public abstract class Entity { public Guid Id { get; set; } public DateTime DateCreated { get; set; } public DateTime DateLastModified { get; set; } public string CreatedBy { get; set; } public string LastModifiedBy { get; set; } public bool Active { get; set; } protected Entity()

AutoMapper, Call Mapper.Map() inside a custom type converter?

对着背影说爱祢 提交于 2019-12-10 23:06:01
问题 I am currently testing with AutoMapper, but i currently have a case where the property names do not match each other, so a custom type convert was needed. But when i use the custom type converter, i have to map all other properties manually? i can't call another Map inside the type converter ofcourse as this will cause a overflow. This is unwanted as there are at most 3 model specific properties that do not match per model so i DO want the other properties to be automaticaly mapped. Could

Which is the best approach? AutoMapper against implicit (C# Reference)

橙三吉。 提交于 2019-12-10 21:51:50
问题 Automapper is a way to match types, ideally when you want to map a model and its viewmodel. But is this not the same approach that we can make with implicit in C#? (Suppose that both model have the same properties but with different names, on this case, you need to specify in AutoMapper which is linked between models) With autommaper we have public class Employee { public string Name { get; set; } public string Email { get; set; } } public class EmployeeViewItem { public string Name { get;