Search code examples
linq-to-entitiesautomapperwcf-ria-services

Mapping an EntityObject to POCO and back in WCF RIA services causes duplicate child entities


I created a complete Visual Studio 2010 solution that can reproduce the issue here:

http://dl.dropbox.com/u/42317133/WcfRiaAutoMapper.zip

  1. Build the solution.
  2. Run the unit test in the test project to deploy the database.
  3. Debug the SilverlightApplication1 project
  4. Click on the "Click me" button.
  5. Notice that two Authors are added to the Authors database table when only one was expected.

The problem exists during the mapping in the InsertPost method in BlogService.cs in the "RIAServicesLibrary1.Web" project.

If I comment those two lines out, then it works as expected.

Any ideas?

This happens with both AutoMapper 1.1 and AutoMapper 2.0.0

Thank you very much.

This is re-post of the issue submitted here:
https://github.com/AutoMapper/AutoMapper/issues/165


Solution

  • I was finally able to resolve this by using the UseDestinationValue member option as follows:

    Mapper.CreateMap<Post2, Post>().ForMember(destinationMember => destinationMember.Author, memberOptions => memberOptions.UseDestinationValue());