automapper

Automapper Map DataTable to POCO list

我们两清 提交于 2020-01-03 20:34:08
问题 Trying to convert a DataTable to a POCO list. Found some answers to that topic at StackOverflow and I thougth everything should be O.K. but I doesn't get the correct result. The result is an empty list of five items. So there is no mapping from the DataRow to the POCO object. Any thoughts what can be wrong? AutoMapper is version 6.1.1 AutoMapper.Data version 1.0.0 class Program { static void Main( string[] args ) { var config = new MapperConfiguration( cfg => { cfg.CreateMissingTypeMaps =

Validation of nested models in view model in ASP.Net MVC

不羁的心 提交于 2020-01-03 18:34:11
问题 I have an application with a Company model. The Company model has a navigation property to an Address model (one-to-one relationship): Company.cs public class Company { public int CompanyID { get; set; } public string Name { get; set; } // Snip... public virtual Address Address { get; set; } } I've created a view model to handle the edit, detail, and create actions: CompanyViewModel.cs public class CompanyViewModel { public int CompanyID { get; set; } [Required] [StringLength(75, ErrorMessage

How to make AutoMapper truncate strings according to MaxLength attribute?

老子叫甜甜 提交于 2020-01-03 13:16:23
问题 I have a DTO I want to map to an entity. The entity has some properties decorated with the MaxLength attribute. I would like AutoMapper to truncate all the strings coming from the DTO when mapping to my entity according to the MaxLength for each property, so that I don't get validation errors when saving the entity. So, if entity is defined like this: public class Entity { [MaxLength(10)] string Name { get; set; } } I would like that doing this: var myDto = new MyDto() { Name =

Is it possible to map IQueryable<CatDTO> to IQueryable<CatEf>?

情到浓时终转凉″ 提交于 2020-01-03 12:59:59
问题 This is a question for Automapper professionals. I have tried to do query mapping for several days already - and no luck. Seems like Automapper is not intended to be used the way I want to use it. But maybe I am wrong. So here is the question... I have such classes: CatDto (Name, Age, Toys (collection of ToyDto objects)) ToyDto (CatName, ToyName, Cat (parent CatDto object)) Cat (comes from Entity Framework, has properties similar to those in CatDto) Toy (comes from Entity Framework, has

Automapper Mapping Multiple Properties to Single Property

给你一囗甜甜゛ 提交于 2020-01-03 12:57:53
问题 I am need help mapping my Domain Object to a ViewModel for use with my C#/MVC App In the FormAnswer Class there can only be 1 Answer Type (AnswerCurrency, AnswerDateTime, AnswerBool,etc) this is enforced in the Database and Application Logic. If a Answer exists it will needs to be to Mapped to the Answer Property in the FormAnswerModel if all values are null the Answer is a Empty String. public class FormQuestion { public int Id {get; set;) public string DataType {get; set;} public string

AutoMapper implementation in ASP.NET Core MVC

匆匆过客 提交于 2020-01-03 11:33:15
问题 I am trying to implement AutoMapper in an ASP.NET Core MVC application using the techniques described in https://lostechies.com/jimmybogard/2016/07/20/integrating-automapper-with-asp-net-core-di. Here is my startup.cs public IServiceProvider ConfigureServices(IServiceCollection services) { … services.AddMvc(); services.AddAutoMapper(); … // Autofac configuration return ConfigureAutofacContainer(services); } Here is my AutoMapper.Profile implementation public class AutoMapperProfile_NetCore

Automapper: Map single object with list of objects inside to just list

为君一笑 提交于 2020-01-03 09:03:18
问题 I have the following dto object: public class PriceDto { public string Ticker {get; set;} public double Open {get; set;} public double Close {get; set;} } The source objects: public class RemoteData { public Security Security { get; set; } public IList<Prices> Prices{ get; set; } } public class Security { public string Ticker {get; set;} } public class Prices { public double Open {get; set;} public double Close {get; set;} } In result, I want to get collection of PriceDto objects. I know how

Easiest way to convert Func<IQueryable<T>, IOrderedQueryable<T>> to Func<IQueryable<U>, IOrderedQueryable<U>>

谁都会走 提交于 2020-01-03 04:40:11
问题 I am trying to convert Func<IQueryable<T>, IOrderedQueryable<T>> to Func<IQueryable<U>, IOrderedQueryable<U>> using AutoMapper as follows: MapperConfiguration config = new MapperConfiguration(cfg => { cfg.CreateMap<Func<IQueryable<T>, IOrderedQueryable<T>>, Func<IQueryable<U>, IOrderedQueryable<U>>>(); }); config.CreateMapper(); Mapper mapper = new Mapper(config); var orderableOfU = mapper.Map<Func<IQueryable<U>, IOrderedQueryable<U>>>(orderableOfT); But it does not work! I am getting the

Convention-based object-graph synchronization

佐手、 提交于 2020-01-02 23:01:32
问题 I'm planning my first architecture that uses DTOs. I'm now exploring how to map the modified client-side domain objects back to the DTOs that were originally retrieved from the data service. I must map back to the original object graph, instead of instantiating a new one, in order to use WCF Data Services Client Library's change tracking feature. To put it in general terms, I need a tool that maps instances and (recursively) their sub-instances (collectively called the "source graph") to

Automapper: How to not repeat mapping config from complex type to base class

蹲街弑〆低调 提交于 2020-01-02 19:25:19
问题 I have a bunch of DTO classes that inherit from this CardBase : // base class public class CardBase { public int TransId {get; set; } public string UserId { get; set; } public int Shift { get; set; } } // one of the concrete classes public class SetNewCardSettings : CardBase { // specific properties ... } In my MVC project I have a bunch of view models with a AuditVm complex type that has the same properties of CardBase : public class AuditVm { public int TransId {get; set; } public string