AutoMapper / AutoMapper.Collection

AutoMapper support for updating existing collections by equivalency
MIT License
245 stars 59 forks source link

Calling EqualityComparison with outer property #147

Closed dalibor-sanzeru closed 4 years ago

dalibor-sanzeru commented 4 years ago

Hi, Is scenario where EqualityComparison is not 1:1 between DTO <-> ENTITY in meaning entity needs to take some equality value from outer dto object? Entity itself identity has one column of parent and one own column. See class example.

Is there any way how to handle these ??? in EqualityComparison with given class structure?

CreateMap<InnerDto, InnerDb>().EqualityComparison((dto, o) => dto.Name== o.Name && dto.??? == o.OuterId);

class OuterDto {
  public int Id { get; set;  }
  public List<InnerDto> InnerDtos { get; set; }
}

class InnerDto {
  public string Name { get; set; }
}

class InnerDb {
  public string Name { get; set; }
  public int OuterId { get; set; }
}

THANKS FOR HELP.

dalibor-sanzeru commented 4 years ago

Is this repo Alive?

Tasteful commented 4 years ago

Yes, the repo is active, it's an open source project without paid members so no dedicated resources asdigned on this, all members are working on spare time with this.

I dont think it's possible to do without modification.

dalibor-sanzeru commented 4 years ago

Hi @Tasteful. Not possible without modification means update AutoMapper.Collection code itself => new feature.

Correct? Thanks for answer.

Tasteful commented 4 years ago

From you 'InnerDto' you need to have a property reference to the 'OuterDto' to be able to do the lookup. It does not exists any way in AM to find the parent object during the mapping without the reference what I know about. Without support in AM it's hard to add support in AM.Collection.

dalibor-sanzeru commented 4 years ago

From you 'InnerDto' you need to have a property reference to the 'OuterDto' to be able to do the lookup. It does not exists any way in AM to find the parent object during the mapping without the reference what I know about. Without support in AM it's hard to add support in AM.Collection.

Thanks for explanation.