Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with AutoMapper
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Titre:
Problem with AutoMapper
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01607877
Message ID:
01607877
Vues:
43
UPDATE. Never mind, this code solved the problem
  Mapper.CreateMap<EditSalespointViewModel, SalesPt>()
                .ForMember(dest=>dest.Salespoint, opt=>opt.MapFrom(source=>source.SalespointKey))
                .ForMember(dest =>dest.ScanOnly,
                    opt => opt.ResolveUsing<ByteToBooleanResolver>().FromMember(source =>  (Byte) source.ScanOnly));
Hi everybody,

In my model I have Boolean column. In the View Model I defined this column (property) as public Enum (type Byte).

In my AutoMapper config I have
   .ForMember(dest =>dest.ScanOnly,
                    opt => opt.ResolveUsing<ByteToBooleanResolver>().FromMember(source => source.ScanOnly));
However, I get an error here

AutoMapper.AutoMapperMappingException was unhandled by user code
HResult=-2146233088
Message=Value supplied is of type SysManager.Common.Enums.AllowablePassNumberEntryMethods but expected System.Byte.
Change the value resolver source type, or redirect the source value supplied to the value resolver using FromMember.
Value supplied is of type SysManager.Common.Enums.AllowablePassNumberEntryMethods but expected System.Byte.
Change the value resolver source type, or redirect the source value supplied to the value resolver using FromMember.

I don't want to write custom resolver. I can, of course, just change the value in the view model to be Byte and not Enum, but is there is way to somehow fix it in the config?

I tried
dest=> Convert.ToByte(dest.ScanOnly)
but this can not be done. So, do you see my problem and how can I resolve it?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Répondre
Fil
Voir

Click here to load this message in the networking platform