You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following example demonstrates a problem where the NullableExpressionBinder is selected even though a custom ProjectUsing expression is configured. This results in an InvalidOperationException
No coercion operator is defined between types 'System.String' and 'System.Nullable`1[AutomapperEnumTest.Method]'.
using System;
using System.Linq;
using AutoMapper;
using AutoMapper.QueryableExtensions;
namespace AutomapperEnumTest
{
public enum Method
{
MANUAL = 0,
AUTO = 1
}
public class DestType
{
public string Name { get; set; }
public Method? Method { get; set; }
}
public class SourceType
{
public string Name { get; set; }
public string MethodName { get; set; }
}
public class Program
{
public static void Main()
{
Configure();
var src = new SourceType[] { new SourceType { Name = "Rob", MethodName = "AUTO" } };
var results = src.AsQueryable()
.ProjectTo<DestType>();
}
private static void Configure()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<string, Method?>().ProjectUsing(src => src == "MANUAL" ? Method.MANUAL : Method.AUTO);
cfg.CreateMap<SourceType, DestType>()
.ForMember(dest => dest.Method, opt => opt.MapFrom(src => src.MethodName));
});
}
}
}
Perhaps the ExpressionBuilder class should change the order of Builders so that CustomProjectionExpressionBinder is listed first?
The text was updated successfully, but these errors were encountered:
The following example demonstrates a problem where the NullableExpressionBinder is selected even though a custom ProjectUsing expression is configured. This results in an
InvalidOperationException
Perhaps the
ExpressionBuilder
class should change the order ofBuilders
so thatCustomProjectionExpressionBinder
is listed first?The text was updated successfully, but these errors were encountered: