Question

I'm having trouble trying to get ValueInjector to map my objects correctly. This is the code I am using for the mapping:

public IEnumerable<CategoryDTO> FindCategories(IList<object[]> criteria)
{
    IEnumerable<Category> categories = _categoryRepo.Find(criteria);
    IEnumerable<CategoryDTO> categoriesDto = Mapper.Map<IEnumerable<Category>, IEnumerable<CategoryDTO>>(categories);
    return categoriesDto;
}

the variable categories contains a property:

IEnumerable<Standard> Standards

This property contains two Standard objects in the instance I'm calling on. The problem is when I map from my Category to my CategoryDTO. CategoryDTO is defined as this:

public class CategoryDTO : AuditableDTO
{
    public Guid CategoryId { get; set; }
    public string Name { get; set; }
    public string MachineName { get; set; }
    public string Description { get; set; }
    public IEnumerable<StandardDTO> Standards { get; set; }
}

After the mapping statement is run, and I investigate the contents of categoriesDto.Standards, I can see that it is null. I would have expected my Standards to have mapped, but I'm sure I'm missing something with ValueInjector. Probably something along the lines of telling it how to map Standard to StandardDTO. Any thoughts?

EDIT: I need to clarify, I'm using this http://valueinjecter.codeplex.com/wikipage?title=Automapper%20Simulation&referringTitle=Home

EDIT 2: Digging deeper, I can see that my Iesi.Collections.HashedSet is causing the issue. Categorys' Standards property are typed as Iesi.Collections.ISet, this is turned into the HashedSet. So I guess my real question is how do I check the property for that type and how can I map?

Était-ce utile?

La solution

My guess would be that the Mapper.Map doesn't know to map one level deeper than the IEnumerable. Have you tried looping though the collection, mapping it at the Category, CategoryDTO level vs the IEnumerable level?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top