automapper

Efficient way of mapping data from Redis

早过忘川 提交于 2019-12-24 17:26:09
问题 I'm playing around with Redis and with ServiceStack.Redis as a client. I initially used 'AutoMapper' to map the cached objects into domain objects, but this was pretty slow. Using someone else's example, I set up a custom mapper but this, too, is really slow. Is there something glaringly wrong with the below code? It's taking 4-5 seconds to map 1000 items from Redis. It's the 'GetByIds' client method that's introducing the lag, but I want an efficient way to store collections as lists of IDs

MapTo() inside of LINQ returning multiple iterations of same data

蓝咒 提交于 2019-12-24 17:24:49
问题 I am using .NET Core with the ASP.NET Boilerplate framework. In some code that I was given to fix, we had a GetAll() method that was supposed to return a collection of rows from the MsSql database. The original code: public IEnumerable<GuidelineCategoriesDto> GetAll(bool activeFilter = true) { return _guidelineCategoriesRepo.GetAll().Select(x => x.MapTo(new GuidelineCategoriesDto())).ToList(); } The problem I was running into with this method, is that it would return the latest row that had

Does AutoMapper's convention based mappings work with LINQ extension methods?

守給你的承諾、 提交于 2019-12-24 11:29:32
问题 I apologize if this is a duplicate but I did not find anything that seemed to be matching up with what I am looking for. As we all know in Automapper we can perform convention based mappings... My Question Is it possible to access extension methods (LINQ.First()) on objects in a collection, to go "n" levels deep? See example below My Entities public class Store { public IList< Departments > Departments {get;set;} } public class Departments { public bool Open {get;set;} } What I want to be

Automapper configuration

那年仲夏 提交于 2019-12-24 10:09:14
问题 Is it enought to call Mapper.Initialize in Application_Start() in global.asax or should some IoC container take care of the lifetime scoping ? protected void Application_Start() { Mapper.Initialize(x=>x.AddProfile(new SomeProfile())); } 回答1: Should be enough. I've never had a problem with initializing Automapper this way. 来源: https://stackoverflow.com/questions/5537192/automapper-configuration

How to Configure AutoMapper Attributes in ASP.NET MVC

空扰寡人 提交于 2019-12-24 08:38:19
问题 According to the GitHUb documentation, To use AutoMapper.Attributes need three steps to be done as follows: Create the classes you'd like to map. Add the [MapsTo] attribute to the source class, with the destination type as the argument. (Alternatively, you can use the [MapsFrom] attribute to map the destination class with the source type.) Call the MapTypes() extension method on the assembly from which you want to map your types. I have done the step 1 and step 2 but can not understand how to

Skip property on update in NHibernate

。_饼干妹妹 提交于 2019-12-24 08:22:53
问题 Say I have an User entity and it haves a Password property which is not nullable : Map((x) => x.Password).Column("PASSWORD").Not.Nullable(); In the create action, I manually set the Password value as it is a generated hash. It never goes to the View. In the update, I try to save it, but I don't have the Password value. I get this error for Password propery: PropertyValueException: not-null property references a null or transient value This is my Update method: public bool Update(UserViewModel

AutoMapper map from collection of IConfigurationSection with complex mapping

我的梦境 提交于 2019-12-24 03:42:21
问题 It is my second question on the topic. My first question is here. Roman Marusyk provided an easy answer to the question. However, I have more difficult case in reality and it will get even more complex. Therefore, I need to use AutoMapper to map the config (though I would be very happy and surprised if default binding coped with this as well). Here is my real json with models followed: { "startupConfig": { "noSubscription": { "calls": [ { "percentage": 30, "techPriority": 1, "timePriority": 2

AutoMapper can't prevent null source values if not all source properties match

泪湿孤枕 提交于 2019-12-24 03:17:03
问题 The goal here is to ignore null source values, while not requiring the source object to have all the fields the destination object has. Preventing null seems to only work if ALL fields match between objects. public class ApiStudent { public long Id { get; set; } public string Name { get; set; } } public class DomainStudent { public long Id { get; set; } public string Name { get; set; } public long SchoolId { get; set; } } When I run the following mapping: Mapper.CreateMap<ApiStudent,

AutoMapping Array to a List

≯℡__Kan透↙ 提交于 2019-12-24 00:47:19
问题 class A { public List<string> list; } class B { public string[] array; } How would you map this? I've tried CreateMap<A,B>(); That doesn't work 回答1: Your first issue is going to be that the class members don't match. If they did, I'd imagine that this would work. If not, you just have to specify your mapping rather than letting Automapper infer it: CreateMap<A,B>() .ForMember(d => d.array, opts => opts.MapFrom(s => s.list.ToArray()); 回答2: For a shortcut, a vb.net version CreateMap(Of A, B)()

NHibernate one expression can be specified in the select list when the subquery is not introduced with EXISTS

亡梦爱人 提交于 2019-12-24 00:45:30
问题 I am having class which contain property which is list of some other class. I want to map this class to another class in queryable extension. AutoMappper.CreateMap<Department1, Department2>() AutoMapper.CreateMap<Employee1, Employee2>() var employee1 =_session.Query<Employee1>(); employee1.Project().To<Employee2>(); It give error 'Could not excecute query Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.' select employee1_.Id as col_0_0_,