Automapper missing type map configuration or unsupported mapping - Error

前端 未结 12 1503
旧时难觅i
旧时难觅i 2020-11-27 16:25

Entity Model

public partial class Categoies
{
    public Categoies()
    {
        this.Posts = new HashSet();
    }

    public int Id { get; se         


        
12条回答
  •  一整个雨季
    2020-11-27 16:57

    I created a new AutomapperProfile class. It extends Profile. We have over 100 projects in our solution. Many projects have an AutomapperProfile class, but this one was new to this existing project. However, I did find what I had to do to fix this issue for us. There is a Binding project. Within the Initialization there is this code:

    var mappingConfig = new List>();
    
    // Initialize the Automapper Configuration for all Known Assemblies
    mappingConfig.AddRange( new List>
    {
       ConfigureProfilesInAssemblyOfType,
       //...
    

    I had to add ConfigureProfilesInAssemblyOfType<MyNewNamespace.AutomapperProfile>

    Note that ConfigureProfilesInAssemblyOfType looks like this:

        private static void ConfigureProfilesInAssemblyOfType( IConfiguration configuration )
        {
            var log = LogProvider.Get( typeof (AutomapperConfiguration) );
    
            // The Automapper Profile Type
            var automapperProfileType = typeof (Profile);
    
            // The Assembly containing the type
            var assembly = typeof (T).Assembly;
            log.Debug( "Scanning " + assembly.FullName );
    
            // Configure any Profile classes found in the assembly containing the type.
            assembly.GetTypes()
                .Where( automapperProfileType.IsAssignableFrom ).ToList()
                .ForEach( x =>
                {
                    log.Debug( "Adding Profile '" + x.FullName + "'" );
                    configuration.AddProfile( Activator.CreateInstance( x ) as Profile );
                } );
        }
    

    Best regards, -Jeff

提交回复
热议问题