0

I have two entities and I need to do an automapper but it is not working:

I have configured the map:

public static class AutoMapperWebConfiguration
{
    public static void Configure()
    {
        ConfigureUserMapping();

    }

    private static void ConfigureUserMapping()
    {            
        Mapper.CreateMap<MyEntity, MyEntityDTO>().ReverseMap();           

    }


}

MyEntity:

public class MyEntity : MongoRepository.Entity
{
    public string Name { get; set; }
}

MongoRepository.Entity:

// Summary:
//     Abstract Entity for all the BusinessEntities.
[Serializable]
[BsonIgnoreExtraElements(Inherited = true)]
public abstract class Entity : IEntity<string>
{
    protected Entity();

    // Summary:
    //     Gets or sets the id for this object (the primary record for an entity).
    [BsonRepresentation(BsonType.ObjectId)]
    public virtual string Id { get; set; }
}

MyEntityDTO:

public class MyEntityDTO
{
    public string Id { get; set; }
    public string Name { get; set; }
}

Trying to map:

var edto = new MyEntityDTO {Id = Guid.NewGuid().ToString(), Name = "Test"};
var e = Mapper.Map<MyEntityDTO, MyEntity>(edto);

Error:

{"Missing type map configuration or unsupported mapping.\r\n\r\nMapping types:\r\nMyEntityDTO -> MyEntityExample\r\nEcoavantis.Interactive.Service.MyEntityDTO -> Ecoavantis.Interactive.Service.MyEntity\r\n\r\nDestination path:\r\nMyEntity\r\n\r\nSource value:\r\nEcoavantis.Interactive.Service.MyEntityDTO"}

chemitaxis
  • 13,889
  • 17
  • 74
  • 125
  • 1
    Your `edto` variable is of type `EntityDTO` (which is not mapped), not `MyEntityDTO` (which is mapped), therefore I suspect that Automapper doesn't know the type. Also, your Automapper configuration is the other way around (see http://stackoverflow.com/questions/2439024/automapper-bidirectional-mapping). – Maarten Aug 27 '14 at 09:15
  • Sorry, my mistake writing the code... I'm using this package: http://mongorepository.codeplex.com/ – chemitaxis Aug 27 '14 at 09:16
  • Your configuration defines a mapping from Entity to DTO, while you are attempting to map from DTO to Entity. – Maarten Aug 27 '14 at 09:17
  • And the reverse? I think it works for making the reverse automapper – chemitaxis Aug 27 '14 at 09:18
  • This seems to work fine for me: https://dotnetfiddle.net/GHZC3t. Is there something else going on in your setup? Can you show the whole stacktrace of the exception? – Andrew Whitaker Aug 27 '14 at 14:00
  • Oh! I Solved the problem, because I was using a Windows Console Program, but the automapper configuration was not loading correctly. – chemitaxis Aug 28 '14 at 06:34

0 Answers0