Mapping objects graphs of DTO's to EF Entities using AutoMapper

362 Views Asked by At

How good is Entity Framework at detecting changes made to objects if using a tool like AutoMapper to move DTO data into entities?

e.g.

var existing = dbcontext.First(e => e.Id = dto.Id);
Mapper.Map(dto,existing);

I know this works fine for single objects or very naive examples.

But how well does it actually play if there is a real graph?

e.g.

Lets assume we have data like this:

dtoOrder.detail[0].product = getSomeProduct();

var existing = dbcontext.First(e => e.Id = dtoOrder.Id);
Mapper.Map(dtoOrder,existing);

I assume EF will think that the new product assigned to detail [0] is a new object? since AutoMapper will not know where to get that entity from.

So, is it possible to use AutoMapper to safely two way map data from DTO's to Entities when working with real objects graphs and not naive examples only?

0

There are 0 best solutions below