Replies: 3 comments 2 replies
-
That repro is too complicated. You need to make it like the example below. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi, using AutoMapper;
var config = new MapperConfiguration(c =>
{
c.CreateMap<Entity1, Entity1Map>();
c.CreateMap<TagData, TagData2>();
});
config.AssertConfigurationIsValid();
var mapper = config.CreateMapper();
try
{
var testService = new TestService();
var entities = testService.GetEntity1s();
var mapEntities = mapper.Map<IEnumerable<Entity1Map>>(entities);
}
catch (Exception ex)
{
ex.ToString();
}
public class Entity1Map
{
public int Id { get; set; }
public string Name { get; set; }
public IData2 Tags { get; set; }
}
public class Entity1
{
public int Id { get; set; }
public string Name { get; set; }
public TagData Tags { get; set; }
}
public class TagData
{
public string Tag { get; set; }
}
public class TagData2 : IData2
{
public string Tag { get; set; }
}
public interface IData2
{
}
public class TestService
{
public IEnumerable<Entity1> GetEntity1s()
{
return new List<Entity1>
{
new Entity1
{
Id = 1,
Name = "Entity1",
Tags = new TagData
{
Tag = "TestData"
}
}
};
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
You need
But I don't see what generics have to do with this repro. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I want to map Entity1 to Entity1Map and TagData to TagData2.
the TagData2 is implemented IData2 you can see the mapping configuration below.
It works in v10.2.2 not in v11.0.0. I also tested it in 11.0.1-alpha.0.9. it doesn't work.
The Generic type mapping also changed in v11.0.0
I can do the below mapping for Generic type in v10
but now I have to specify the type
CreateMap(typeof(type1), typeof(type1));
Source/destination types
Try to map Entity1 to Entity1Map
Mapping configuration
Version: 11.0.0
Expected behavior
Should be able to map to target type
Actual behavior
Error mapping types.
Missing type map configuration or unsupported mapping.
Mapping types:
TagData -> IData2
Project1.TagData -> Project1.IData2
Destination Member:
Tags
Steps to reproduce
Framework: .net6
IDE: VS2022
I have attached a demo project
Project1.zip
Beta Was this translation helpful? Give feedback.
All reactions