AutoMapper / AutoMapper.Collection

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

Non Generic EqualityComparison #154

Closed nkovacic closed 2 years ago

nkovacic commented 3 years ago

Is a non-generic version of EqualityComparison supported?

CreateMap(typeof(Model), typeof(ModelDto))
      .EqualityComparison((src, dest) => (src as BaseEntity).Id == (dest as BaseEntity).Id)
TylerCarlson1 commented 3 years ago

No. If you want to make something that will generate equality based off some convention you can look into LinqToSQL and EF extensions. there's an equality method generator interface that you can use to make your own comparisons if need be. Like match any public properties that have Id and match name or just Id.

nkovacic commented 3 years ago

I am assuming that you have to make an custom IGeneratePropertyMaps like the AutoMapper.Collection.EFCore does with GenerateEntityFrameworkCorePrimaryKeyPropertyMaps. Are there any examples for this?

TylerCarlson1 commented 3 years ago

There are no custom examples. You can look at GenerateEntityFrameworkCorePrimaryKeyPropertyMaps source code and see how it works there. It uses reflection from the DBContext to get the Primary Keys and then returns property maps that use said keys.