Questions tagged [automapper-2]

Use this tag for version specific questions about AutoMapper 2 - the convention-based object-to-object mapper and transformer library for .NET. When using this tag also include the more generic [automapper] tag where possible.

113 questions
4
votes
2 answers

Automatic discovery of automapper configurations

When you create a controller in MVC, you don't have to do any additional registration for it. Same goes with adding areas. As long as your global.asax has an AreaRegistration.RegisterAllAreas() call, no additional setup is necessary. With…
danludwig
  • 46,965
  • 25
  • 159
  • 237
4
votes
1 answer

automapper boolean properties to yes or no

For a mapping between TypeA and TypeB i would like all the boolean properties to be mapped to 'Yes' or 'No'. I don't want to override the mapping since i want that just for the mapping between TypeA and TypeB. And I would not like to…
Julien
  • 833
  • 8
  • 20
3
votes
1 answer

AutoMapper Change Type

Given the following: var object1 = new A() { Equipment = new List() { new FooEquipment() } }; var object2 = new B() { Equipment = new List() { new FooEquipment() } ); var list = new List() { object1, object2…
Sebastian Patten
  • 7,157
  • 4
  • 45
  • 51
3
votes
3 answers

How to optimize Entity Framework query when using spatial types and automapper?

What I'm building is not something very unique. In a nutshell I'm creating a small FourSquare like service running in Azure using ASP.NET MVC 4(Web Api) and Entity Framework 5 (with Spatial support). So I'm using SQL Azure and not one of the NoSQL…
Saab
  • 981
  • 3
  • 11
  • 34
3
votes
2 answers

Automapper merge/combine mappings

Let's assume I have these mappings: var mapping1 = Mapper.CreateMap() .ForMember(o => o.Referrer, m => m.Ignore()); var mapping2 = Mapper.CreateMap() .ForMember(o => o.Price, m => m.Ignore()); var mapping3…
Dennis
  • 1,027
  • 1
  • 14
  • 30
3
votes
1 answer

How to force Automapper to overwrite array property?

I am using Automapper in my project to map business entities to DTO. public class TransportStop { public Point[] Points { get; set; } } public class TransportStopDto { public PointDto[] Points { get; set; } public TransportStopDto() …
3
votes
1 answer

AutoMapper Map properties of nested objects if Not Null

I have the following sample objects.. public class ComplexObject { public string Name { get; set; } public SimpleObject Child1 { get; set; } public SimpleObject Child2 { get; set; } } public class SimpleObject : IEquatable<…
andycwk
  • 826
  • 2
  • 9
  • 19
3
votes
1 answer

Memory leak - any guesses where it can be

I'm working on .Net project (windows service) and I found memory leak. Using ANTS Memory profiler, I've determined - root cause is in unmanaged memory scope. But I don't use any COM/COM+ or p/invoke - pure .Net (DataAcces - Fluent nHibernate,…
Andriy Zakharko
  • 1,623
  • 2
  • 16
  • 37
2
votes
2 answers

Automapper: How to leverage a custom INamingConvention?

I am working with a database where the designers really seemed to enjoy capital letters and the underscore key. Since I have a simple ORM, my data models use these names as well. I need to build DTOs and I would prefer to give them standard names…
nachonachoman
  • 802
  • 1
  • 13
  • 29
2
votes
2 answers

Castle Windsor does not resolve AutoMapper profiles after update

Everything was working fine until I updated with NuGet the references for CastleWinsor and AutoMapper to their latest versions: Castle.Windsor.3.0.0.4001 and AutoMapper.2.0.0. I have a list of AutoMapper profiles in the same assembly as the…
noir
  • 566
  • 2
  • 5
  • 19
2
votes
1 answer

Two way mapping with automapper using same objects and different TypeConverters

I want to use AutoMapper for mapping DTO s to Models. But my project contains some custom rules for default values for primitive types like [string null value is "_"], [default int value is -1] and [date time fields must be integer like 19990221]…
2
votes
0 answers

ConstructUsing protected constructor

By default, Automapper is able to use protected constructors for mapping. However, it just takes the one with most suitable parameters and uses it. How could I tell Automapper which protected constructor to use?
starteleport
  • 1,231
  • 2
  • 11
  • 21
2
votes
0 answers

Automapper 2 - unflattening entity to VM

I have a flat POCO Entity and a structured View Model (that is used for rendering a form with custom EditorFor helpers). Is there any easier way in Automapper 2 to do something like that: cfg.CreateMap
2
votes
0 answers

AutoMapper throwing NullReferenceException when mapping nullable enum to null

I can't seem to figure out why AutoMapper is throwing an exception for this mapping: public class MyDestinationType { public MyCustomEnum? PropName { get; set; } } public enum MyCustomEnum { Val1, Val2 } Mapper.CreateMap
danludwig
  • 46,965
  • 25
  • 159
  • 237
2
votes
2 answers

How to prevent values in "Target" object being overwritten by nulls from "Source" object when using ValueInjector or Automapper? Nested Mapping Issue?

My Problem "Source" object Properties of the same class that do not exist in the View, are overwritting the same properties in the "Target" object with nulls. How do I prevent this? In affect how do I ensure only populated(not null) properties are…
EdB
  • 449
  • 6
  • 21