mam jednostki:jak odwzorować anonimowy obiekt na klasę przez AutoMappera?
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; }
}
i model:
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; }
}
i zapytań jednostce tak (przez EF lub NH):
var tagsAnon = _context.Tags
.Select(t => new { Tag = t, PostsCount = t. Posts.Count() })
.ToList();
Teraz, jak mogę mapować tagsAnon
(jako ano nymous object) do kolekcji TagModel
(np. ICollection<TagModel>
lub IEnumerable<TagModel>
)? Czy to możliwe?
Dlaczego nie map 'Tag' bezpośrednio do' TagModel'? Dlaczego obiekt pośredni? –