automapper

Can I force Automapper to initialise properties in a certain order?

被刻印的时光 ゝ 提交于 2019-12-12 03:19:44
问题 I'm using Automapper and the Queryable Extensions to project some (similar) models into the same DTO in order to concatenate and sort them for paging on the DB server (via Entity Framework) without returning the data until it is paged. var tasksType1 = context.TasksType1.Project().To<MyDto>(); var tasksType2 = context.TasksType2.Project().To<MyDto>(); var allTasks = tasksType1.Concat(tasksType2); return allTasks.ToMyPagedList() This works well, except that now my models have got slightly more

Automapper, mapping objects by linked association?

会有一股神秘感。 提交于 2019-12-12 02:59:57
问题 Lets say I have these models public class Mouse { public string Cheese { get; set; } } public class Cat { public string Hairball { get; set; } } public class Dog { public string ChewyToy { get; set; } } And I map a Mouse to a Cat then a Cat to a Dog: Mapper.CreateMap<Mouse, Cat>().ForMember(m => m.Hairball, o => o.MapFrom(src => src.Cheese)); Mapper.CreateMap<Cat, Dog>().ForMember(m => m.ChewyToy, o => o.MapFrom(src => src.Hairball)); By extension, a Mouse should also be mapped to a Dog,

map configuration or unsupported mapping

跟風遠走 提交于 2019-12-12 02:30:00
问题 I have two types. One in the business layer: namespace Business { public class Car { private int _id; private string _make; private string _model; public int id { get { return _id; } set { _id = value; } } public string make { get { return _make; } set { _make = value; } } public string model { get { return _model; } set { _model = value; } } } } and the other in the Data layer (Entity Framework): namespace Data { using System; using System.Collections.Generic; public partial class Car {

How do I use automapper to map many-to-many relationships?

眉间皱痕 提交于 2019-12-12 02:17:38
问题 We're working on a project that has a user consisting of roles, and the roles consist of more granular functions, and we're trying to map the many-to-many relationships of the DTOs to our Business Objects. Here's an example of the DTOs: public class UserDto { public Guid Id { get; set; } public string Username { get; set; } public virtual ICollection<UserRoleDto> UserRoles { get; set; } } public class UserRoleDto { public virtual Guid UserId { get; set; } public virtual UserDto User { get;

how do I map this using Automapper

自闭症网瘾萝莉.ら 提交于 2019-12-12 02:15:02
问题 I am in need to map the below scenario. public class Customer { public string CustomerJson { get; set; } } public class CustomerTO { public object CustomerJson { get; set; } } From DAL I get CustomerJson value as below. Customer.CustomerJson = { "name": "Ram", "city": "India" } I am in need to Deserialize this string. so I tried the below stuff while mapping. var config = new MapperConfiguration(cfg => { cfg.CreateMap<Customer, CustomerTO>() .ForMember(dest => dest.CustName, opt => opt

Getting Automapper error when trying to map nested objects

♀尐吖头ヾ 提交于 2019-12-12 02:13:15
问题 I have a Box object which has a list of SerialNumber objects nested within it. I'm trying to map the SerialNumberName property of each SerialNumber in each Box to a model called BoxedElectrodesModel . Here is my Box class and its nested SerialNumber class: public partial class Box { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public Box() { this.SerialNumbers = new HashSet<SerialNumber>(); } public int BoxID { get;

How to use Automapper 5?

强颜欢笑 提交于 2019-12-12 01:46:21
问题 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

Switch between configurations in AutoMapper

限于喜欢 提交于 2019-12-12 00:21:26
问题 I have this situation: // Core Business classes public class Invoice { public Guid Id { get; protected set; } public int Number { get; set; } public IList<InvoiceItem> Items { get; protected set; } } public class InvoiceItem { public Guid Id { get; protected set; } public string Product { get; set; } public int Quantity { get; set; } public decimal Price { get; set; } } // MVC Models public class InvoiceModel { public Guid Id { get; set; } public int Number { get; set; } public IList

AutoMapping nested models

梦想的初衷 提交于 2019-12-11 20:08:54
问题 I'm attempting to automap a model from a provider project to a wcf data contract. However they both have another model/data contract inside the original (Nested). For example: We have a client model, holds information such as name, phone number, EIN, etc... However each client can have multiple contacts (another model). How would I map this in automapper using the fluent mapping? below are the classes. DataContracts Client data contract using System.Collections.Generic; using System.Runtime

Should AutoMapper be used to Map from ViewModel back into Model?

南楼画角 提交于 2019-12-11 17:22:41
问题 Should AutoMapper be used to take data from ViewModel and save back into a database model? I know the opposite practice is good software practice: to have Automapper to extract database models, and place them in Viewmodels for front end web applications. I was reading this general article here: The article was not specifically about Automapper, but want to validate if the opinion is true. best way to project ViewModel back into Model "I believe best way to map from ViewModel to Entity is not