I have an existing object that I would like to update with the latest data from my database. I can currently retrieve the EF Core object and then call Mapper.Map to update my dto. Is there a way to use ProjectTo (or something similar) to update my object from the database?
Instead of this:
var result = await context.DbSet
.FirstOrDefaultAsync(e => e.Id == id, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return Mapper.Map(result, existingObject);
How can I:
var result = await context.DbSet
.ProjectTo<TDest>(/* existingObject */) // I tried .Map, but I got an error that automapper was trying to map this to a child object
.FirstOrDefaultAsync(e => e.Id == id, cancellationToken: cancellationToken)
.ConfigureAwait(false);
return existingObject; // Where existingObject contains the latest database information