Używam funkcjonalności Projektu w Automapper i Entity Framework, ale pojawia się problem, w którym Automapper nie chce wyświetlać jednego typu wyliczeniowego na inny.Automapper nie może wyświetlić jednego typu wyliczeniowego na inny
Mam następujące podmioty:
public class UserProfile
{
public Guid Id { get; set; }
public string Name { get; set; }
private HashSet<UserProfilePhone> m_Phones;
public virtual HashSet<UserProfilePhone> Phones
{
get { return m_Phones ?? (m_Phones = new HashSet<UserProfilePhone>()); }
set { this.m_Phones = value; }
}
}
public class UserProfilePhone
{
public PhoneType Type { get; set; }
public virtual string Number { get; set; }
}
public enum PhoneType
{
Home = 1,
Work = 2,
Mobile = 3,
Other = 4
}
I wtedy jestem wystające te typy do następujących modeli:
public class UserProfileModel
{
public Guid Id { get; set; }
public virtual string Name { get; set; }
public IEnumerable<UserProfilePhoneModel> Phones { get; set; }
}
public class UserProfilePhoneModel
{
public UserProfilePhoneTypeModel Type { get; set; }
public string Number { get; set; }
}
public enum UserProfilePhoneTypeModel
{
Home = 1,
Work = 2,
Mobile = 3,
Other = 4
}
Potem ustawienia mojego mapowania tak:
Mapper.CreateMap<PhoneType, UserProfilePhoneTypeModel>();
Mapper.CreateMap<UserProfilePhone, UserProfilePhoneModel>();
Mapper.CreateMap<UserProfile, UserProfileModel>();
I wreszcie wykonuję swoją projekcję:
var result = dbContext.UserProfiles.Project().To<UserProfileModel>();
Kiedy to zrobić, pojawia się następujący wyjątek:
AutoMapper.AutoMapperMappingException: Nie można utworzyć mapę ekspresji z MyNamespace.PhoneType do MyNamespace.Models.UserProfilePhoneTypeModel Nie można utworzyć mapę wyrażenie z MyNamespace.PhoneType do MyNamespace.Models.UserProfilePhoneTypeModel Wynik stackTrace:
na System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func
2 valueFactory) ...
Próbowałem tworzyć jawne odwzorowania, ale wydają się one ignorowane. Co ja tu robię źle?
możliwe duplikat [Automapper wyliczenia wyliczają klasa] (http://stackoverflow.com/questions/24453398/automapper-enum -to-enumeration-class) –