This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi guys, I am using auto mapper to map from my domain to dto's and then back again. I am running into some problems, firstly, each time i am mapping from the dto to the domain, the entitystate is always new and creates a new entity. If i find the existing entity, then map it, the children are then created as a new entity and the existing ones deleted. I have create a test app to see if it was an issue i had caused, and i get the same result in the test app. public Dtos.Snippet SaveSnippet(Dtos.Snippet snippet)
{
Snippet entity = null;
using (CodeBankModelUnitOfWork uow = Context.CurrentUnitOfWork)
{ Below is the class for the automapper configuration public class MappingProfile:AutoMapper.Profile
{
protected override void Configure()
{
/* Entity to DTO */
this.CreateMap
Due to the fact automapper can not set the entity's Id and the unit of work import does not import children, is there an easier way to achieve this??? All i am trying to do is convert entities to dto's, send across the wire and then add them back to a unit of work and save any additions or changes. Any help would be greatly appreciated. Mike. |
|
|
Hi Mike, If you need to force the Id on an Entity (we don't recommend this but I understand your scenario) then you can use reflection to achieve this, e.g. assuming you are using Int64 identity values:
|
|