FAQ Database Discussion Community


What could be reason of AutoMapper failed?

c#,automapper
I suppose that reason of AutoMapper failed is slightly different fields of domain model and view model. Here is domain model: public partial class Users { public int Id { get; set; } public string Login { get; set; } public string Password { get; set; } public int RoleId...

'AutoMapper.AutoMapperMappingException' occurred in AutoMapper.dll

c#,asp.net-mvc,automapper
public class ClientViewModel { [Required(ErrorMessage = "The Client Code field is required.")] public string ClientCode { get; set; } [Required(ErrorMessage = "The Company Legal Name field is required.")] public string CompanyLegalName { get; set; } public string Notes { get; set; } public string Address { get; set; }...

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

c#,automapper
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...

An object in the Automapper is returning null

c#,automapper
I am trying to work on a sample example to map CustomerViewItem(Source) and Customer(Destination). Here is the Source Entities that I am trying to map public class CustomerViewItem { public CompanyViewItem companyViewItem { get; set; } public string CompanyName { get; set; } public int CompanyEmployees { get; set; }...

Mapping flattened stored proc values to navigation property

sql,entity-framework,mapping,entity-framework-6,automapper
Here is my stored procedure which returns a type of Customer_GetCustomers_Result: SELECT c.*, a.City AS AddressCity, a.State AS AddressState FROM Customer c LEFT OUTER JOIN Address a ON c.AddressId = a.Id I expect AddressCity and AddressState to map to Customer.Address.City and Customer.Address.State when using AutoMapper to map from Customer_GetCustomers_Result to...

What's the alternative to IValueFormatter in AutoMapper?

c#,asp.net-mvc,automapper
So I started using AutoMapper for my ASP.NET MVC project, looked at a couple of examples and wrote my first IValueFormatter implementation when a blue wiggly popped up for IValueFormatter: Interface 'AutoMapper.IValueFormatter' is obsolete: "Formatters should not not be used". Well, okay, then how am I supposed to e.g. convert...

Querying and mapping complex objects using Linq-to-SQL

c#,linq-to-sql,automapper
I have the following two tables: ChildTable ID ManyColumns ParentID 1 XXXX 1 2 YYYY 1 3 ZZZZ 4 ParentTable ID Name 1 aaaa 2 bbbb 3 cccc 4 dddd I have the following classes representing the above tables: public class Child { public string ID { get; set; }...

Map dto to complex entity

c#,automapper,dto,automapper-3
How can I map the complex UploadDTO to the entity Number? public class UploadDTO { public CustomerDTO Customer { get; set; } public MachineDTO Machine { get; set; } public NumberDTO Number { get; set; } } public class Number { public Customer Customer { get; set; } public Machine...

MVC Mapping between View Model and Request-Response messaging pattern

asp.net-mvc,design-patterns,automapper,asp.net-mvc-viewmodel
I have the following MVC design pattern issue and confused which way to go. In the UI layer, a View Model is used in a Controller action method. Cool. The Service layer uses the Request-Response message pattern, so the service class method has a Request object as a parameter (in),...

Custom MappedEntityDomainManager throws StackOverflowException

stack-overflow,automapper,azure-mobile-services
I created a custom MappedEntityDomainManager to map my data objects to the DTOs. For the last couple of day I'm trying to figure out in a TableController why it throws a StackOverflowException. This is the only MappedEntityDomainManager I have so far to test AutoMapper. The data object and DTO model....

Automapping only under specific namespace

c#,automapper,fluent-nhibernate-mapping
I don't know why but with this settings automap tries to map BaseClass too, how can I fix this? The entity 'BaseClass`1' doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id). _sessionFactory = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(ConnectionString).ShowSql()) .Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Foo.E.MenuItem>() .Where(t =>...

Automapper missing type map configuration or unsupported mapping

entity-framework,mongodb,automapper,repository-pattern,nuget-package
I have 2 class : Class 1 : (Domain) public class Book { public ObjectId Id { get; set; } public String ISBN { get; set; } public String Title { get; set; } public String Publisher { get; set; } public int? PageCount { get; set; } public Author...

Controlling Namespace Prefixes in WCF XML Output

c#,xml,wcf,automapper
The current output of my WCF service is as follows (only a portion is shown below): <s:Body> <executeSelectSP2Response xmlns="http://tempuri.org/"> <executeSelectSP2Result xmlns:a="http://schemas.datacontract.org/2004/07/WCF_Services.DataContract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <a:Rows> <a:RowDetail> <a:Fields> <a:FieldDetail> <a:name>STATE_CD</a:name> <a:value>1</a:value> </a:FieldDetail> <a:FieldDetail>...

'AutoMapper.Configuration' is a 'namespace' but is used like a 'type'

unity,automapper,ioc-container,automapper-3
I am trying to upgrade AutoMapper 1.1 to AutoMapper 3.3. I have the following statement in my current code that does not work in v3.3 container.RegisterType<IConfiguration, global::AutoMapper.Configuration>(new ContainerControlledLifetimeManager()); container is a Unity container. I am getting the following error. 'AutoMapper.Configuration' is a 'namespace' but is used like a 'type' How...

AutoMapper test fails on implicit widening conversion in TeamCity build but not locally

visual-studio-2013,teamcity,automapper
I have the following AutoMapper configuration: Mapper.CreateMap<Source, Dest>() .ForMember(dest => dest.InitiatorUserAccountUID, opt => opt.UseValue(0)); InitiatorUserAccountUID is of type long. The Mapper.AssertConfigurationIsValid() unit test passes locally, but fails on TeamCity with the following error: AutoMapper.AutoMapperConfigurationException: The following property on System.Int64 cannot be mapped: InitiatorUserAccountUID When I cast 0 to long explicitly...

Mapping joined Domain Model to View Model using Automapper

c#,asp.net-mvc-4,automapper
In my business logic class I am joining two data models and returning back to the controller as IEnumerable. I need to map these collection to the List using automapper .But it is not working as expected. Logic class public IEnumerable<object> GetPurchaseOrderDetailsByPersonId(long personId) { var purchaseOrderDetails = from pom in...

Strange mapping behaviour from String to Boolean

c#,.net,azure,automapper
By mistake, someone from my project wrote in the automapper profile the following sentence: Mapper.CreateMap<Appointment, AppointmentModel>() .ForMember(x => x.DeclineStart, o => o.MapFrom(x => x.DeclineStart.ToString())) Where DeclineStart is the property of the entity and the model classes. public class Appointment { public bool DeclineStart { get; set; } } public class...

Automapper AfterMap function initialising classes

.net,vb.net,automapper
Can anyone please explain how does the AfterMap function initalises the class objects passed in the lambda expression? When i run this bit of code as myself, it populates the dest object with my details. i can't figure out how is it doing that? but if someone can tell me...

How can I map types in a class library without mapped classes leaking from that library

c#,entity-framework,automapper
I have a web project and a class library and I need to map types in the library, for example namespace Library { public class Type1 { ... } internal class Type2 { ... } public class Repository : IRepository { private readonly IMappingEngine mappingEngine; public Repository(..., IMappingEngine mappingEngine) {...

AutoMapper: An exception of type 'AutoMapper.AutoMapperMappingException' occurred in AutoMapper.dll but was not handled in user code

c#,mapping,automapper,dto
I have a problem like this. But this answer it didn't work for me. I am working on a little project. I have two domain model (Post, Source): public class Post { public Post() { Sources = new HashSet<Source>(); } public int Id { get; set; } public string Title...

Automapper starting exception in Windows 8.1 Unified project

c#,.net,windows-phone-8.1,automapper,mvvmcross
I have a cross-platform project, using mvvmcross and stuff. Right now, solution consists of Core and Windows Phone projects. Core contains AutoMapper reference, and WP project contains AutoMapper and AutoMapper.WPA references. Application works fine in most cases, but sometimes it throws exceptions like Could not load file or assembly 'AutoMapper.Net4'....

Automapper append source list items to destination list

automapper
I am trying to map List<string> property but I want in destination object to always have default value. On the source object list can be empty or it can contain other values. If the list is empty then the Destination property will contain only the default value that is defined...

AutoMapper: Unable to cast object of type 'System.Linq.Expressions.MethodCallExpressionN' to type 'System.Linq.Expressions.MemberExpression'

c#,linq,automapper
From what I've read from this error, f.E. here: Why are some object properties UnaryExpression and others MemberExpression? This happens, when an object is expected, but an value type is returned, so the CLR has to pack this, which is another (Unary)expression. What really bothers me, the following AutoMapper-Mapping works...

Using AutoMapper to map a string to an enum

c#,.net,automapper
I have the following classes domain and Dto classes: public class Profile { public string Name { get; set; } public string SchoolGrade { get; set; } } public class ProfileDTO { public string Name { get; set; } public SchoolGradeDTO SchoolGrade { get; set; } } public enum SchoolGradeDTO...

AutoMapper with different instances

c#-4.0,entity-framework-6,automapper
I have two classes public class PatientViewModel { public int Id { get; set; } public string FirstName { get; set; } public string MiddleName { get; set; } public string LastName { get; set; } public DateTime DOB { get; set; } } and public class PatientExtended : PatientViewModel...

Missing type map configuration or unsupported mapping - AutoMapper

wcf,c#-4.0,automapper
I am trying to map an Entity Framework Code First class to a WCF DataContract class using AutoMapper. The code is as follows: [DataContract] public class User { [DataMember] public int UserId { get; set; } [DataMember] public string UserName { get; set; } [DataMember] public string Password { get;...

AutoMapper AfterMap

c#,automapper
I have some code that pretty much looks like below, see working example at https://dotnetfiddle.net/wuE81t. public class Program { public static void Main() { Mapper.CreateMap<Foo, Bar>() .AfterMap((s, d) => { var stuff = SomeController.GetStuff(DateTime.Now.Second); d.Stuff = stuff.Contains(s.Name); }); var foo = new List<Foo>() { new Foo() { Name = "joe",...

AutoMapper referencing a map within a map

c#,automapper
Really struggling with how I might accomplish this, I'm basically trying to feed my Index view a list of ClubViewModel but to do this I need to match up my list of Club. I'm using AutoMapper and everything is working well apart from the CalendarEntry stuff which is a List...

AutoMapper map one list to two equally sized lists with derived properties

c#,automapper
So I have a source object with one list, the list includes two types of values but I would like for the destination to have two list, one for each value but in the same resulting property. I hope the example here is self explanatory. My Source: public class SourceObject...

Denormalise object hierarchy with automapper

c#,automapper,automapper-3
I know various questions have been asked that resembles this question, but as far as I can tell (and test), none of the provided solutions seems to fit, so here goes. I am wondering if it is possible to flatten/denormalise an object hierarchy so that an instance with a list...

How to convert double to nullable int, int to nullable int in AutoMapper?

c#,.net,automapper
I had to fight with this for a while. I was using AutoMapper to map between different numeric formats and constantly getting errors when mapping int to int? etc. Now, I could have modified my DTO objects to match accordingly, but it wasn't so easy. I understand this is primarily...

How to configure Automapper to automatically ignore properties with ReadOnly attribute?

c#,.net,asp.net-mvc,mapping,automapper
Context: Let's say I have the following "destination" class: public class Destination { public String WritableProperty { get; set; } public String ReadOnlyProperty { get; set; } } and a "source" class with the ReadOnly attribute on one of it's properties: public class Source { public String WritableProperty { get;...

Do AutoMapper IQueryable extensions still work with EF 6.1?

c#,entity-framework,automapper
I keep getting Exceptions when trying to resolve entities with AutoMapper into viewmodels and I can't figure out why. The following code Mapper.CreateMap<Article, ArticleViewModel>() .ForMember(a => a.CreatedDate, a => a.ResolveUsing<DateResolver>()) .ForMember(a => a.Content, a => a.ResolveUsing<ContentResolver>().ConstructedBy(() => new ContentResolver(articleParserFactory))); var test = this.context.Articles .Project() .To<ArticleViewModel>() .ToArray(); always leads to an...

Automapper with MVC and modified nested entities - how to update them

asp.net-mvc,entity-framework,asp.net-mvc-5,automapper
I'm using automapper to map my entities to a viewmodel, and form the viewmodel back to the entity on the trip back from the view. I've got a little problem, I have a nested entities list in my modified object, which can be modified in the view. When I save...

Automapper Projection and LINQ queries with EF6

linq,entity-framework-6,automapper
We have a legacy system with support for multiple languages. The language specific fields is duplicate on each database row - per language with language code as column name prefix. In our EF6 model we us a LocalizedString complex type to hold all the translated values for each string property....

AutoMapper file size formatting

c#,asp.net,.net,automapper
I have wrote a ValueResolver to convert a file size to a nicer looking string version. Problem is, ValueResolver takes a specific object type. Is there a way to write the same code, but be able to apply it against any number property i want? here is the ValueResolver public...

Map ICollection to List using AutoMapper

c#,linq,automapper
I'm trying to use AutoMapper in my code. When mapped the collection, I've got this error LINQ to Entities does not recognize the method 'System.Collections.Generic.List1[Web.ViewModels.FirmMatterViewModel] Map[ICollection1,List1](System.Collections.Generic.ICollection1[Web.Models.FirmMatter])' method, and this method cannot be translated into a store expression. This is the code how I do the mapping: var clientMatters = from...

Mapping complex DTOs to entities with automapper

c#,automapper,automapper-3
I want to map from LDTTicketUploadDTO[] to IEnumerable<LDTTicket> The mappings are created in this method and at the end I map the data. public void UploadLDTTickets(LDTTicketUploadDTO[] ticketDTOs) { Mapper.CreateMap<LDTTicketUploadDTO, LDTTicket>(); Mapper.CreateMap<LDTTicketDTO, LDTTicket>(); Mapper.CreateMap<LDTCustomerDTO, LDTCustomer>(); Mapper.CreateMap<LDTDeviceDTO, LDTDevice>(); Mapper.CreateMap<LDTUnitDTO, LDTUnit>(); Mapper.CreateMap<LDTCommandDTO, LDTCommand>();...

Using Automapper with a collection of abstract objects

c#,automapper
Please take a look at this rather contrived example of what I'm trying to do. First, the database models: public class Report { public Guid Id { get; set; } public string Name { get; set; } public ICollection<Worker> Workers { get; set; } } public abstract class Worker {...

AutoMapper DataServiceCollection to List

automapper,automapper-2,automapper-3
I am attempted to use AutoMapper to map a DataServiceCollection to a list of strings and also create the reverse mapping. Any ideas on how to map a specialized collection like this to another? Mapper.CreateMap<DataServiceCollection<LocationCountyValue>, List<string>>(); ...

Automapper mapping 2 entities to a single class

automapper
Just wondering if this is possible: Say I have a ViewModel for comparing an old and new entity. public class FooComparison { public string Name {get;set;} public string OldName {get; set;} public int Age {get; set;} public int OldAge {get; set;} ... } I want to load 2 instances of...

Deep Copy of Complex Third Party Objects/Classes [duplicate]

c#,clone,automapper,deep-copy,valueinjecter
This question already has an answer here: Deep cloning objects 25 answers I'm have been working on a project to create PDF forms using PDFView4Net. While the library is generally good, the forms creator is primitive and lacking basic features (such as copy/paste, alignment, formatting, etc.) when working with...

join two different list by id into one list

c#,list,join,merge,automapper
I've got two different list of two different objects. Then i got one list of a viewmodel that contains properties from both the objects and i want them to be joined into that list. //Product public string id { get; set; } public string unitMeasurement { get; set; } public...

Flatten Nested List using AutoMapper

c#,.net,automapper
I'm trying to flatten a nested object into a DTO object in .NET 3.5. Most of what I've seen so far is to use AutoMapper to do this (using v1.x since I need to use .NET 3.5, unfortunately): Here's what a snippet of my class structures look like: public class...

Creating a DateTime using AutoMapper

c#,viewmodel,automapper
I am struggling to create a DateTime object from (year, month, day) which is being returned from the database. I am rather new to AutoMapper so a nudge in the right direction would be great. Here is the ViewModel containing the DateTime object and the three values that need to...

Is it good practice to use object-object mappers, and, if so, where to use it?

asp.net-mvc,model-view-controller,automapper,object-object-mapping
I've googled some around the internet and found some articles about the subject, but none of them satisfied me. I want to know is it good to use object-object mapper to map objects to each other? I know it depends on situation to use, but how will I realize a...

Map a dozen of hierarchical objejcts with AutoMapper to DTOs

c#,automapper,automapper-3
I have a hierarchy of 12 entity framework objects. I have also for each entity a DTO created. I want to send the DTOs over the wire. I have to use the DTO-approach. How would you map this amount of objects with Automapper? Do I have to use 12 times...

Automapper v3.3.1.0 Missing type map configuration or unsupported mapping

c#,asp.net-mvc,mapping,automapper
I get the error Missing type map configuration or unsupported mapping. Version of AutoMapper: v3.3.1.0 My code is: Global.asax protected void Application_Start() { AutoMapperWebConfig.RegisterMappings(); AutoMapperServiceConfig.RegisterMappings(); } AutoMapperWebConfig: public class AutoMapperWebConfig { public static void RegisterMappings() { Mapper.Initialize(cfg => { cfg.AddProfile<DtoToViewModelMappingProfile>(); }); } } AutoMapperServiceConfig: public class AutoMapperServiceConfig { public static...

How to Get Mapper by BaseType

c#,asp.net-mvc,automapper
I want to get commented mapper(AutoMapper.Mapper.FindTypeMapFor) by using base type. Is it possible to get it like in the usage AutoMapper.Mapper.CreateMap<IEntity, ListItemModelBase>() .Include<Book, BookListItemModel>(); AutoMapper.Mapper.CreateMap<Book, BookListItemModel>() .ForMember( a => a.Author, (a) => a.MapFrom( entity => entity.Author.Name)) .ForMember(a => a.Genre, (a) => a.MapFrom( entity => entity.Genre.Name)); AutoMapper.Mapper.CreateMap<BookListItemModel, Book>();...

Inject ISession into custom valueresolver

nhibernate,asp.net-web-api,dependency-injection,automapper,structuremap
I'm trying to inject an instance of ISession into a custom AutoMapper ValueResolver. Here's the resolver public class ContactTypeResolver : ValueResolver<Common.Models.ContactType, Models.ContactType> { ISession _session; public ContactTypeResolver(ISession session) { _session = session; } protected override Models.ContactType ResolveCore(Common.Models.ContactType source) { return _session.Load<Models.ContactType>(source.Id); } } I have a profile for setting up...

How to ignore destination member with AutoMapper?

c#,automapper
I have these 2 classes: public class MyModel() { public int Id {get; set;} public string Name {get; set;} public bool IgnoreModel {get; set;} } public class MyDto() { public int Id {get; set;} public string Name {get; set;} public bool IgnoreDto {get; set;} } I want to ignore both...

Automapper returns null object, source object is not null. Why is that so?

c#,asp.net,.net,automapper,asp.net-web-api2
So I have this WebApiPrice.Web.Api.Models.Category class /* * Service model class, that will represent categories */ using System; using System.Collections.Generic; namespace WebApiPrice.Web.Api.Models { public class Category { private List<Link> _links; public long CategoryId { get; set; } public string Name { get; set; } public DateTime Timestamp { get; set;...

Projecting from an IDbAsyncQueryProvider

entity-framework,async-await,automapper
I have a project in which we use Automapper to Project() entities from our data access layer into our domain classes which are consumed by external callers (i.e. WebAPI, windows services, etc). The idea is that we want to abstract our domain model from the actual database implementation, but often...

Flatten and map objects inner collection to another collection

c#,automapper
I have a source enumeration which holds an inner enumeration, IEnumerable<>. I want to be able to take my sources inner enumeration and flatten it out into my destination enumeration. However, when I attempt the following code below, I am prompted with an exception stating that this is an invalid...

Automapper ignore property on generics mapping

c#,.net,automapper
This generic method works fine : public static U PropertyAutomapper<T, U>(T source) where T : class, new() where U : class, new() { Mapper.CreateMap(typeof(T), typeof(U)); return Mapper.Map<T, U>(source); } I have this interface : public interface IPassword { string Password { get; set; } } I'd like ignore this property...

Creating a group of test objects with AutoMapper

automapper
I'm trying to create a repository of data that I can use for testing purposes for an emerging car production and design company. Beginning Automapper Question: In this project, I have 2 classes that share the same properties for the most part. I don't need the Id, so I am...

How to use AutoMapper with PagedList?

c#,asp.net-mvc,automapper,pagedlist
I'd like to use AutoMapper in order to map my ViewModel to domain model class. Also I'm using PagedList NuGet Package. I'm using it this way: [Authorize] [AutoMap(typeof(ErrorsLog), typeof(ErrorsLogViewModel))] public ActionResult Errors(string searchString, string currentFilter, int? page) { if (searchString != null) { page = 1; } else { searchString...

Updating existing domain model using AutoMapper sets NULL

c#,.net,entity-framework,automapper
I have the below viewmodel which is same as domain model (but includes some extra properties). public class ProductViewModel { public string Name { get; set; } public string ShortDescription { get; set; } public string FullDescription { get; set; } public string AdminComment { get; set; } } From...

Automapper Enum Description Attribute

c#,automapper
I'm having difficulties mapping from an Enum Description Attribute. I've been looking all over for a useful example with very little luck. I know there are some other examples out there but I'm still struggling with this particular scenario. Here is my Enum: public enum ResolveCodeEnum { [Description("Resolved - Workaround")]...

Mapping separate fields into one string using Automapper

c#,string,field,concatenation,automapper
I have spent a couple of days trying to track this down without any luck. I have a table of addresses. Each row has 4 address fields. I want to map them to another object that has one field that is a single string made up of the 4 fields,...

Automapper and NHibernate: lazy loading

c#,nhibernate,fluent-nhibernate,automapper
I have the following scenario. public class DictionaryEntity { public virtual string DictionaryName { get; set; } public virtual IList<DictionaryRecordEntity> DictionaryRecord { get; set; } } public class DictionaryDto { public string DictionaryName { get; set; } public IList<DictionaryRecordEntity> DictionaryRecord { get; set; } } I'm using Automapper and NHibernate....

Trying to map System.Collections.Generic.List 1 Exception is thrown

c#,automapper
I am trying to map RecordDTO and Record. But when I run the application, an exception is thrown. RecordBL recordBL = new RecordBL(); List<Record> record = recordBL.GetAllRecords(); Mapper.CreateMap<RecordDTO, Record>(); List<RecordDTO> recordDTO = Mapper.Map<List<Record>,List<RecordDTO>>ecgrecord); Mapper.AssertConfigurationIsValid(); return recordDTO; The exception is something like this: Trying to map System.Collections.Generic.List1[[Server.BusinessEntities.Record, Server.BusinessEntities,...