Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As @Stef mentioned you must map each entry in the collection individually, like this</p> <pre><code>_testEntities.Join(_testDtos, e =&gt; e.Id, e =&gt; e.Fk_Id, (entity, dto) =&gt; Mapper.Map(dto,entity)); </code></pre> <p>Here the full functionally example:</p> <pre><code>[TestClass] public class AutoMapperTests { private readonly IEnumerable&lt;Dto&gt; _testDtos; private readonly IEnumerable&lt;Entity&gt; _testEntities; public AutoMapperTests() { _testDtos = new List&lt;Dto&gt; { new Dto() { Id = 0, Fk_Id = 8, Price = 350000 } }; _testEntities = new List&lt;Entity&gt; { new Entity() { Id = 8, Price = 68000 } , new Entity() { Id = 6, Price = 350000 } }; } [TestInitialize] public void TestInitialize() { Mapper.Reset(); } [TestMethod] public void AutoMapperIgnore_TwoCollectionsWithOneCommonElementMappedFromDtoToEntityIgnoreId_SameWithUnchangedIdAndNewPrice() { //Assign Mapper.CreateMap&lt;Dto, Entity&gt;() .ForMember(destination =&gt; destination.Id, opt =&gt; opt.Ignore()); AutoMapperIgnore_TwoCollectionsWithOneCommonElementMappedFromDtoToEntity_SameWithUnchangedIdAndNewPrice(true); } [TestMethod] public void AutoMapperIgnore_TwoCollectionsWithOneCommonElementMappedFromDtoToEntityUseDestinationtValueForId_SameWithUnchangedIdAndNewPrice() { //Assign Mapper.CreateMap&lt;Dto, Entity&gt;() .ForMember(destination =&gt; destination.Id, opt =&gt; opt.UseDestinationValue()); AutoMapperIgnore_TwoCollectionsWithOneCommonElementMappedFromDtoToEntity_SameWithUnchangedIdAndNewPrice(true); } private void AutoMapperIgnore_TwoCollectionsWithOneCommonElementMappedFromDtoToEntity_SameWithUnchangedIdAndNewPrice(bool isExceptedSame) { //Assign var exceptedPrice = _testDtos.First().Price; //Act Entity entityBeforeMapping = _testEntities.First(testEntity =&gt; testEntity.Id == _testEntities.First().Id); IEnumerable&lt;Entity&gt; foundEntities = _testEntities.Join(_testDtos, e =&gt; e.Id, e =&gt; e.Fk_Id, (entity, dto) =&gt; Mapper.Map(dto,entity)); Entity entityAfterMapping = foundEntities.First(); //Assert if (isExceptedSame) { Assert.AreSame(entityBeforeMapping, entityAfterMapping); } Assert.AreEqual(entityBeforeMapping.Id, entityAfterMapping.Id); Assert.AreEqual(exceptedPrice, entityAfterMapping.Price); } [TestMethod] public void AutoMapperIgnore_TwoObjectMappedWithIgnoreId_SameWithUnchangedIdAndNewPrice() { //Assign Mapper.CreateMap&lt;Dto, Entity&gt;() .ForMember(destination =&gt; destination.Id, opt =&gt; opt.Ignore()); var testDto = new Dto() { Id = 0, Fk_Id = 8, Price = 350000 }; var testEntity = new Entity() { Id = 8, Price = 68000 }; var exceptedPrice = testDto.Price; //Act Entity entityBeforeMapping = testEntity; Mapper.Map(testDto, testEntity); Entity entityAfterMapping = testEntity; //Assert Assert.AreSame(entityBeforeMapping, entityAfterMapping); Assert.AreEqual(entityBeforeMapping.Id, entityAfterMapping.Id); Assert.AreEqual(exceptedPrice, entityAfterMapping.Price); } internal class Dto { public int Id { get; set; } public int Fk_Id { get; set; } public Single? Price { get; set; } } internal class Entity { public int Id { get; set; } public Single? Price { get; set; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload