Automapper with related entity

Asked

Viewed 216 times

1

Good afternoon,

How to map the following entities

public class Artista
    {

        public Artista()
        {
            ArtistaCategoria = new List<ArtistaCategoria>();
        }

        public int ArtistaId { get; set; }
        public string Nome { get; set; }
        public string Email { get; set; }

        public DateTime DataCadastro { get; set; }
        public DateTime DataAtualizacao { get; set; }

        public virtual ICollection<ArtistaCategoria> ArtistaCategoria { get; set; }
    }


public class ArtistaCategoria
    {
        public int ArtistaCategoriaId { get; set; }
        public int ArtistaId { get; set; }
        public int CategoriaId { get; set; }

        public virtual Artista Artista { get; set; }
        public virtual Categoria Categoria { get; set; }
    }


public class Categoria
    {

        public int CategoriaId { get; set; }
        public string Nome { get; set; }
        public virtual ICollection<ArtistaCategoria> ArtistaCategoria { get; set; }
    }

I am using Automapper and I am not able to recover the categories in the list of artists.

ex.

// aqui tenho as categorias
var a = _artistaApp.GetAll();

// após mapear, as categorias não são listadas
var aVM = Mapper.Map<IEnumerable<Artista>, IEnumerable<ArtistaViewModel>>(a);
  • You have set the Artist Mapping to ArtistaViewModel ? ex: Mapper.CreateMap<Artista>, ArtistaViewModel>... and initialized the configuration of the AutoMapper in ArtistaViewModel Global.asax ? Or all properties are loaded except categories ?

  • yes mapping configured, and yes it is configured in the global..

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.