Ho un'entità:come mappare un oggetto anonimo in una classe con AutoMapper?
public class Tag {
public int Id { get; set; }
public string Word { get; set; }
// other properties...
// and a collection of blogposts:
public ICollection<Post> Posts { get; set; }
}
e un modello:
public class TagModel {
public int Id { get; set; }
public string Word { get; set; }
// other properties...
// and a collection of blogposts:
public int PostsCount { get; set; }
}
e interrogo l'entità simili (da EF o NH):
var tagsAnon = _context.Tags
.Select(t => new { Tag = t, PostsCount = t. Posts.Count() })
.ToList();
Ora, come posso mappare lo tagsAnon
(come un ano nymous object) a una raccolta di TagModel
(ad es. ICollection<TagModel>
o IEnumerable<TagModel>
)? È possibile?
Perché non map 'Tag' direttamente a' TagModel'? Perché l'oggetto intermedio? –