automapper

AutoMapper 3.1.1 and Entity Framework 6.1 Proxy objects

耗尽温柔 提交于 2019-12-01 09:26:24
I realized this has been asked already, but the solutions I've read don't seem to make a difference so far. I'm using Entity Framework 6.1 and AutoMapper 3.1.1. Taking the following objects: Company and CompanyListItem ; I try this: Mapper.Configure<Company, CompanyListItem>(); Well, when I try to do the actual mapping it crashed and burned with an exception that there's no mappings defined. I know this is caused because of the proxy objects created by Entity Framework. One solutions I've seen so far is to call an overloaded version of the Map method: IQueryable<Company> companies =

Automapper returns reference to the same object when mapping sequences to arrays

自作多情 提交于 2019-12-01 09:23:59
I have an extension method for IEnumerable<T> , which maps sequence items and returns an array of clones: public static class AutoMapperExtensions { public static T[] MapToArray<T>(this IEnumerable<T> sequence) { return Mapper.Map<T[]>(sequence); } } Here's code sample, whose behavior is weird from my point: Mapper.CreateMap<SomeClass, SomeClass>(); Mapper.AssertConfigurationIsValid(); // clone list members and store them into array var list = new List<SomeClass> { new SomeClass { MyProperty = 1 }, new SomeClass { MyProperty = 2 }, }; // works fine var array = list.MapToArray(); // let's map

How can I use AutoMapper on properties marked Internal?

不羁的心 提交于 2019-12-01 09:19:33
I have a solution with several projects. A business components project, an MVC web app, a DTO's and ViewModels project, a business component unit test project, and an MVC unit test project. All in all, not too unusual. The business component had a Service reference to several WCF endpoints. Within the business component, the data contracts from the WCF end points gets automapped using AutoMapper into the data necessary for the ViewModels. The problem I wanted to solve was that the data contract POCO's in the autogenerated WCF proxies are all PUBLIC, so when I reference my business component

Automapper overwrites missing source property on list with child objects

[亡魂溺海] 提交于 2019-12-01 09:04:16
I have a problem with Automapper. I set up a test windows form application and below is the code. Also look at the comments after each MessageBox: public class FirstClass { public string FirstProp { get; set; } public IList<FirstClassChild> Children { get; set; } } public class FirstClassChild { public string FirstChildProp { get; set; } } public class SecondClass { public string FirstProp { get; set; } public string SecondProp { get; set; } public IList<SecondClassChild> Children { get; set; } } public class SecondClassChild { public string FirstChildProp { get; set; } public string

Automapper complex types mapping exception

你。 提交于 2019-12-01 08:48:10
I'm trying to implement the AutoMapper for a new module. I have the MVC model at the web site, I'm working on, and it looks like this: public class MvcModel { public Params Params { get; set; } public Steps Steps { get; set; } } public class Params { public int? RequestId { get; set; } public bool NewClient { get; set; } } public class Steps { public Step1 Step1 { get; set; } public Step2 Step2 { get; set; } public Step3 Step3 { get; set; } } public class Step1 { public int Name { get; set; } } public class Step2 { public int Phone { get; set; } } public class Step3 { public int Email { get;

Where to place AutoMapper map registration in referenced dll

我是研究僧i 提交于 2019-12-01 08:10:52
问题 This is my first AutoMapper project and may be obvious to some but the tutorials and examples are not clicking with me. I am trying to understand where and to a certain degree how to register(I think I want profiles) my maps for use. There are plenty of MVC examples saying to use the global asax and this makes sense but what is the equivalent in a library project? In my sandbox I have a winform app and a core library. The winform app calls methods made available by the library and it is one

Automapper returns reference to the same object when mapping sequences to arrays

只谈情不闲聊 提交于 2019-12-01 07:01:27
问题 I have an extension method for IEnumerable<T> , which maps sequence items and returns an array of clones: public static class AutoMapperExtensions { public static T[] MapToArray<T>(this IEnumerable<T> sequence) { return Mapper.Map<T[]>(sequence); } } Here's code sample, whose behavior is weird from my point: Mapper.CreateMap<SomeClass, SomeClass>(); Mapper.AssertConfigurationIsValid(); // clone list members and store them into array var list = new List<SomeClass> { new SomeClass { MyProperty

Generic extension method for automapper

≯℡__Kan透↙ 提交于 2019-12-01 06:35:16
public abstract class Entity : IEntity { [Key] public virtual int Id { get; set; } } public class City:Entity { public string Code { get; set; } } public class BaseViewModel:IBaseViewModel { public int Id { get; set; } } public class CityModel:BaseViewModel { public string Code { get; set; } } my domain and view classes... and for mapping extension public static TModel ToModel<TModel,TEntity>(this TEntity entity) where TModel:IBaseViewModel where TEntity:IEntity { return Mapper.Map<TEntity, TModel>(entity); } and i am using like below City city = GetCity(Id); CityModel model = f.ToModel

How can I use AutoMapper on properties marked Internal?

不羁岁月 提交于 2019-12-01 06:28:03
问题 I have a solution with several projects. A business components project, an MVC web app, a DTO's and ViewModels project, a business component unit test project, and an MVC unit test project. All in all, not too unusual. The business component had a Service reference to several WCF endpoints. Within the business component, the data contracts from the WCF end points gets automapped using AutoMapper into the data necessary for the ViewModels. The problem I wanted to solve was that the data

Automapper overwrites missing source property on list with child objects

≡放荡痞女 提交于 2019-12-01 06:08:16
问题 I have a problem with Automapper. I set up a test windows form application and below is the code. Also look at the comments after each MessageBox: public class FirstClass { public string FirstProp { get; set; } public IList<FirstClassChild> Children { get; set; } } public class FirstClassChild { public string FirstChildProp { get; set; } } public class SecondClass { public string FirstProp { get; set; } public string SecondProp { get; set; } public IList<SecondClassChild> Children { get; set;