I am using virtual keyword for some of my properties for EF lazy loading. I have a case in which all properties in my models that are marked as virtual
You can create a mapping extension and use it:
namespace MywebProject.Extensions.Mapping
{
public static class IgnoreVirtualExtensions
{
public static IMappingExpression
IgnoreAllVirtual(
this IMappingExpression expression)
{
var desType = typeof(TDestination);
foreach (var property in desType.GetProperties().Where(p =>
p.GetGetMethod().IsVirtual))
{
expression.ForMember(property.Name, opt => opt.Ignore());
}
return expression;
}
}
}
Usage :
Mapper.CreateMap().IgnoreAllVirtual();