Is there a way to provide the persistent object to the map method ? #88
Unanswered
MilanRaval
asked this question in
Q&A
Replies: 2 comments 3 replies
-
Sorry, I missed this post! don't know why... Actually you can write your own map method and put this inside of it: var profileKey = ProfileKey.Empty; // default profile.
var entity = new { Id = 1 }; // your tracked entity
var dto = new { Id = 1 }; // some dto, which could be another instace of entity
var mapper = dbContext.GetEntityMapper(); // get the EntityMapper instance associated to the dbContext.
var parameters = new MapParameters(); // create parameters, same as the ones supplied in regular Map
// create a context. this is the link between the mapper and EntityFramework, and it helps to track entity states and apply some behaviors
var context = new EntityMapContext(mapper.Options.ConcurrencyTokens, dbContext, mapper.GetQueryProvider(profileKey), parameters);
// now get the mapper. EntityMapper is a kind of adapter/façade of Mapper, there is 1 mapper per profile
var result = mapper.GetMapper(profileKey).Map(dto, dto.GetType(), entity, entity.GetType(), context); I wouldn't like to add this as a feature, because the QueryProvider should take care of loading the entities and adding the right Includes. etc. |
Beta Was this translation helpful? Give feedback.
1 reply
-
In 7.2 there was a large refactor about this. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to provide the persistent object instance to the map method as a parameter ? And use the Detached Mapper for only comparing and setting entity state ?
Beta Was this translation helpful? Give feedback.
All reactions