Missing type map configuration or unsupported mapping.

162 views
Skip to first unread message

Andrés Gustavo Muñoz Dávila

unread,
Oct 6, 2021, 9:09:02 PM10/6/21
to AutoMapper-users
This is the exception:

CDStructure -> CDStructure

CannedDataGenerator.dbContext.CDStructure -> CannedDataGenerator.Model.CDStructure

   at lambda_method138(Closure , CDStructure , CDStructure , ResolutionContext )

   at lambda_method137(Closure , IEnumerable`1 , IEnumerable`1 , ResolutionContext )

   --- End of inner exception stack trace ---

   at lambda_method137(Closure , IEnumerable`1 , IEnumerable`1 , ResolutionContext )

   at CannedDataGenerator.Provider.CDGeneratorProvider.GetCDAsync() in /Users/andgmd/Projects/WireMock.CannedData/CannedDataGenerator/Provider/CDGeneratorProvider.cs:line 34}

{System.Collections.ListDictionaryInternal}

-2146233088

"ul"

{AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.

 

Mapping types:

CDStructure -> CDStructure

CannedDataGenerator.dbContext.CDStructure -> CannedDataGenerator.Model.CDStructure

   at lambda_method138(Closure , CDStructure , CDStructure , ResolutionContext )

   at lambda_method137(Closure , IEnumerable`1 , IEnumerable`1 , ResolutionContext )}

(null)

"Error mapping types.\n\nMapping types:\nIEnumerable`1 -> IEnumerable`1\nSystem.Collections.Generic.IEnumerable`1[[CannedDataGenerator.dbContext.CDStructure, CannedDataGenerator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> System.Collections.Generic.IEnumerable`1[[CannedDataGenerator.Model.CDStructure, CannedDataGenerator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"

"AutoMapper"

"   at lambda_method137(Closure , IEnumerable`1 , IEnumerable`1 , ResolutionContext )\n   at CannedDataGenerator.Provider.CDGeneratorProvider.GetCDAsync() in /Users/andgmd/Projects/WireMock.CannedData/CannedDataGenerator/Provider/CDGeneratorProvider.cs:line 34"

{TDestination MapCore[TSource,TDestination](TSource, TDestination, AutoMapper.ResolutionContext, System.Type, System.Type, AutoMapper.IMemberMap)}

(null)

"IEnumerable`1", "IEnumerable`1"


MODELS

I am using relational Models

 Main structure


public class CDStructure

 {

        private JObject _mapping;

        [Key]

        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]

        public Guid UUID { get; set; }

        public string Type { get; set; }

        [NotMapped]

        public JObject Mapping

        {

            get

            {

                return this._mapping;

            }

            set

            {

                this._mapping = value;

            }

        }

        public Guid IdRequest { get; set; }

        public Request Request { get; set; }

        public Guid IdResponse { get; set; }

        public Response Response { get; set; }



        [Column("Mapping")]

        public string MappingStr

        {

            get

            {

                return this._mapping.ToString();

            }

            set

            {

                this._mapping = JsonConvert.DeserializeObject<JObject>(value);

            }

        }


        public CDStructure()

        {

        }


    }

Structure A

 public class Request

    {

        private JObject _parameters;

        [Key]

        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]

        public Guid UUID { get; set; }

        public string Url { get; set; }

        public string Verb { get; set; }

        [NotMapped]

        public JObject Parameters

        {

            get

            {

                return this._parameters;

            }

            set

            {

                _parameters = value;

            }

        }



        [Column("Parameters")]

        public string ExtraDataStr

        {

            get

            {

                return this._parameters.ToString();

            }

            set

            {

                this._parameters = JsonConvert.DeserializeObject<JObject>(value);

            }

        }


        public CDStructure CDStructure { get; set; }


        public Request()

        {

        }

    }

Structure B

public class Response

    {

        private JObject _data;

        [Key]

        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]

        public Guid UUID { get; set; }

        public int ResponseCode { get; set; }

        [NotMapped]

        public JObject Data {

            get

            {

                return this._data;

            }

            set

            {

                _data = value;

            }

        }

        public CDStructure CDStructure { get; set; }


        [Column("Data")]

        public string DataStr

        {

            get

            {

                return this._data.ToString();

            }

            set

            {

                this._data = JsonConvert.DeserializeObject<JObject>(value);

            }

        }

    }

I have the same replication under folders Model and dbContex

This is my Context Class

public class CDStructureContext : DbContext

    {

        public DbSet<CDStructure> cdStructure { get; set; }

        public DbSet<Request> request { get; set; }

        public DbSet<Response> response { get; set; }


        public CDStructureContext(DbContextOptions options) :base(options)

        {

            

        }


        protected override void OnModelCreating(ModelBuilder modelBuilder)

        {


            modelBuilder.Entity<CDStructure>()

                    .HasOne(x => x.Request)

                    .WithOne(x => x.CDStructure)

                    .HasForeignKey<CDStructure>(x => x.IdRequest);


            modelBuilder.Entity<CDStructure>()

                .HasOne(a => a.Response)

                .WithOne(b => b.CDStructure)

                .HasForeignKey<CDStructure>(b => b.IdResponse);


        }

    }


Populating the main Structure

string json = @"{id: '1',name: 'John Doe',address: 'St Unknown'}";

                JObject jmapping = JObject.Parse(json);

                json = @"{}";

                JObject jobjparameters = JObject.Parse(json);

                JObject Jobjdata = JObject.Parse(json);

                this._dbContext.cdStructure.Add(new dbContext.CDStructure() { Type = "Json", Mapping = jmapping, Request = new dbContext.Request() { Parameters = jobjparameters, Verb = "GET", Url = "http:/localhost:8080/mockcd" }, Response = new Response() { ResponseCode = 200, Data = Jobjdata } });

                this._dbContext.SaveChanges();

WHERE THE ERROR IS GENERATED

The error it generated when I using Automapper in the next line

var result = this._mapper.Map<IEnumerable<dbContext.CDStructure>, IEnumerable<Model.CDStructure>>(canneddata);


of the following asynchronous task

public async Task<(bool IsSuccess, string message, IEnumerable<Model.CDStructure> canned_data)> GetCDAsync()

        {

            try

            {

                var canneddata = await _dbContext.cdStructure.ToListAsync();

                if (canneddata.Any())

                {

                    var result = this._mapper.Map<IEnumerable<dbContext.CDStructure>, IEnumerable<Model.CDStructure>>(canneddata);

                    return (true, "Getting data", result);

                }

                return (false, "Doesn't contain any record", null);


            }

            catch (Exception ex)

            {

                return (false, ex.ToString(), null);

            }

        }












Reply all
Reply to author
Forward
0 new messages