c#


AutoMapper tiny class to large class with validation


I have a large class with 30+ properties, and I need to map to it from a tiny class with about 6 properties that should map automatically (same name, same Type). I do not want to have to maintain a list of 24+ .Ignore()s in the mapping config, but I do want to be able to run AutoMapper's validation routine against all the rest of my mappings; I don't particularly care if this one mapping is validated, though.
I have tried ReverseMap and some of the Ignore* methods to see what might work. I thought ReverseMap would be the trick, but either I'm using it wrong or it doesn't do what I understand it to do. It does not seem to be well-documented.
For clarity:
public class LargeClass {
// 30+ properties here
}
public class TinyClass {
// 6 properties here that map perfectly to LargeClass
// 4-8 properties that do not map to LargeClass, by design
}
CreateMap<TinyClass, LargeClass>(); // Will not validate, 24+ unmapped properties on Destination :(
Thank you!
ReverseMap is when you want to reverse a map from a CreateMap call.
It sounds like you need to pass in the member list you want to validate against:
CreateMap<TinyClass, LargeClass>(MemberList.Source);
This validates against the source members.
And if you need more documentation, check out the wiki!

Related Links

Storing the state of a ToggleSwitch Into A Variable in C# and XAML
How to set html input text control as invisible at code behind with out using runat=“server”
How to extract particular columns values from multiple rows using linq
Linq grouping from Category to subcategory
Flag Role Enum with JWT Bearer Token and Custom AuthorizeAttribute
Regular expression for string to find only number without decimal point.
ImageResizer: Disable size limitation of resizing
Multiple Select for Edit User Wtih CheckBox
Action Not Firing When Button Clicked
Catch and change keyboard on mac sierra to emulate neo2 keyboard layout
Deserializing JSON using C# to return items
How to make a triangular location in C#?
What is the option in C# having capability of same like 'IN' in SQl
How to configure Visual Studio to not indent closing parenthesis on multiline function calls?
C# Interface base usage
Creating a named .txt file and subsequently writing string to it in C#

Categories

HOME
oauth-2.0
ckan
itunesconnect
sip
packet
arcgis
magento-1.9.2.1
datetimepicker
grid
yuv
opacity
flowtype
clip-path
pip
software-collections
runtime
openbsd
apache-httpclient-4.x
elastalert
virtualenv
swift3.1
hql
web-testing
tag-cloud
facebook-marketing-api
powerpivot
printf
audio-streaming
passbook
android-navigation-drawer
connectiq
prepros
pumping-lemma
inspec
expressionengine
mex
azure-table-storage
kundera
folder
mobile-development
choco
imdb
contextmenustrip
openvms
n1ql
gstreamer-1.0
oracle-bpm-suite
bzip2
datagridviewcombobox
apiman
html-entities
qtwebkit
spring-data-commons
activeandroid
ionic2-select
openxava
enet
ajv
boost-regex
programming-pearls
liferay-ide
dynatable
spring-cloud-aws
tsc
stringbuilder
tinybox2
change-password
bytearray
user-profile
archiva
factorization
oryx
nslocalizedstring
mojolicious
adempiere
jsoncpp
numerical-recipes
applinks
esri-arc-engine
crtdbg.h
uiblureffect
fedena
banana-pi
db2-connect
nomachine
raddatepicker
grape-api
nsautoreleasepool
gssapi
aspmenu-control
google-email-audit-api
scsf
netduino
javah
subdirectories
qlibrary
jgrowl
managed-code
high-load
stackless

Resources

Encrypt Message