Need automapper to map a domain type's properties back to an existing entity from the context (basically just updating the fields that have changed). I need it to ignore Navigation properties and only map the scalar properties.
I can get it to work if I say ForMember(o => o.MyNavProperty, opt => opt.Ignore) but I'd rather have a generic method for all of my mappings to tell it to only map scalar and not nav properties.
Trying to follow Mauricio's solution:
ASP.net MVC - Should I use AutoMapper from ViewModel to Entity Framework entities?
but I can't get it to successfully ignore my navigation properties.
Here's my updated version:
private static void CreateMapForEF<TDto, TEntity>()
{
Mapper.CreateMap<TDto, TEntity>()
.ForAllMembers(o => o.Condition(ctx =>
{
var members = ctx.Parent.SourceType.GetMember(ctx.MemberName); // get the MemberInfo that we are mapping
if (!members.Any())
return false;
if (members.First().GetCustomAttributes(
typeof (EdmRelationshipNavigationPropertyAttribute), false).Any())
return false;
return members.First().GetCustomAttributes(typeof(EdmScalarPropertyAttribute), false).Any(); // determine if the Member has the EdmScalar attribute set
}));
}