automapper

Using AutoMapper to Map IList<TSource> to (Iesi.Collections.Generic) ISet<TDestination>

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have been trying to solve this issue for a day now and have got no where so am hoping someone might have solved this before. The closest I found to a solution was How to simply map an NHibernate ISet to IList using AutoMapper and Map IList to ICollection through AutoMapper but still no joy. I have a data object that looks like: public class Parent { public virtual ISet Children { get ; set ; } } And a business object that looks like: public class ParentDto { public IList Children { get ; set ; } } Using AutoMapper to map from

Need to speed up automapper…It takes 32 seconds to do 113 objects

强颜欢笑 提交于 2019-12-03 01:59:50
问题 Hi I have some major problems with auto mapper and it being slow. I am not sure how to speed it up. I am using nhibernate,fluent nhibernate and asp.net mvc 3.0 [Serializable()] public class Test { public virtual int Id { get; private set; } public virtual string Name { get; set; } public virtual string Description { get; set; } public virtual DateTimeDate { get; set; } public virtual IList<Reminder> Reminders { get; set; } public virtual IList<Reminder2> Reminders2 { get; set; } public

How to use AutoMapper .ForMember?

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to set up AutoMapper to convert from Entity to DTO. I know I'm supposed to be using .ForMember() after Mapper.CreateMap () ,> to set up custom mappings, but this doesn't seem to be an available method. Edit for clarification: I am not looking for a link to the documentation, which I have read, or an explanation of the basic syntax. I am using the correct syntax as described in answers and the documentation, for example: Mapper . CreateMap () . ForMember ( dest => dest . Code , opt => opt . MapFrom ( src => src . Name ))

Automapper: Auto map collection property for a dto object

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a domain object public class ProductModel { public long Id {get;set;} public string Name {get;set;} public string SerialNumber {get;set;} } Single Dto class: public class ProductDto { public long Id {get;set;} public string Name {get;set;} public string SerialNumber {get;set;} } Single Dto class that is a list of Dto object: public class ProductListDto : List { public List Products; public ProductListDto() { Products = new List (); } } And I'd like to map a list of domain objects to list of Dto objects such that the "Products"

Automapper - ReverseMap() does not perform mapping

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following 2 classes: public class ReferenceEngine { public Guid ReferenceEngineId { get; set; } public string Description { get; set; } public int Horsepower { get; set; } } public class Engine { public Guid Id { get; set; } public string Description { get; set; } public int Power { get; set; } } I am using automapper to perform a mapping from ReferenceEngine to Engine and vice versa. Notice that the properties ReferenceEngineId / Id and Horsepower / Power does not have the same name. The following mapping configuration works and

How to use AutoMapper to map destination object with a child object in the source object?

匿名 (未验证) 提交于 2019-12-03 01:11:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the source and destination objects like this: class ProductWithCategories // Source class { public Product Product { get; set; } // Product is an EF entity class public IEnumerable<Category> Categories { get; set; } } class ProductViewModel // Dest class { public int Id { get; set; } // Other properties with the same name as Product class public IEnumerable<CategoryViewModel> Categories { get; set; } } So, my need is to map the values of source.Product into dest , and then source.Categories into dest.Categories . Is it possible with

How to use Automapper latest version?

匿名 (未验证) 提交于 2019-12-03 01:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am new to Automapper. With below links, I am trying to understand it in action. http://automapper.org/ https://lostechies.com/jimmybogard/2016/01/21/removing-the-static-api-from-automapper/ I am using its Automapper v 5.2.0 Here is my stuff. https://codepaste.net/xph2oa class Program { static void Main(string[] args) { //PLEASE IGNORE NAMING CONVENTIONS FOR NOW.Sorry!! //on Startup AppMapper mapperObj = new AppMapper(); mapperObj.Mapping(); DAL obj = new DAL(); var customer = obj.AddCustomers(); } } class Customer { public int CustomerId {

IoC with AutoMapper Profile using Autofac

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 ViewModelAutoMapperConfiguration constructor

How to use Automapper to create complex viewmodel objects from a simple object and a method call

匿名 (未验证) 提交于 2019-12-03 01:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My application needs to display a table of customer data, including data about the customer and about his most recent order from a given warehouse. The customer domain object contains a GetLatestOrder(warehouseId) method. I have a CustomerView viewmodel and want to be able to populate it with some fields from the customer object, and a few fields from the latest order object. Can I do this using Automapper? 回答1: Try this, In Global.asax.cs [ Application_Start ], public static void AppInitialize() protected void Application_Start(object

AutoMapper with Ninject confusion

匿名 (未验证) 提交于 2019-12-03 00:56:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: For starters I'm using this module: public class AutoMapperModule : NinjectModule { public override void Load() { Bind<ITypeMapFactory>().To<TypeMapFactory>(); foreach (var mapper in MapperRegistry.AllMappers()) { Bind<IObjectMapper>().ToConstant(mapper); } Bind<AutoMapper.ConfigurationStore>().ToSelf().InSingletonScope().WithConstructorArgument("mappers", ctx => ctx.Kernel.GetAll<IObjectMapper>()); Bind<IConfiguration>().ToMethod(ctx => ctx.Kernel.Get<AutoMapper.ConfigurationStore>()); Bind<IConfigurationProvider>().ToMethod(ctx => ctx