-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question - mapping multiple classes to a single one ? #184
Comments
Hello! Glad to hear you've found the mapper useful! :) There's been other holes found in mapping validation lately, and I think there might be some missing functionality here. This: mapper.WhenMapping
.From<SourceClass>().ToANew<DestinationClass>()
.Map((source, _) => source.TheCat).To(dest => dest.PetNames)
.And
.Map((source, _) => source.TheDog).To(dest => dest.PetNames); ...errors because we're setting two different data sources for the same target member, and I think that's probably what it should do - maybe we should be able to do this: mapper.WhenMapping
.From<SourceClass>().ToANew<DestinationClass>()
.Map((source, _) => source.TheCat).To(dest => dest.PetNames)
.Then
.Map((source, _) => source.TheDog).To(dest => dest.PetNames); ...with In the meantime, there's this: mapper.WhenMapping
.From<SourceClass>().ToANew<DestinationClass>()
.Map((source, _) => source.TheCat).To(dest => dest.PetNames);
mapper.WhenMapping
.From<SourceClass>().ToANew<PetNames>()
.Map((source, _) => source.TheDog).ToTarget(); But that fails validation because the mapper isn't figuring out that applying Thanks for the feedback, and happy new year! Steve |
Thank you for your reply, I will work on a workaround on my side. I like your mapper.WhenMapping
.From<SourceClass>().ToANew<DestinationClass>()
.Map((source, _) => source.TheCat).To(dest => dest.PetNames)
.And
.Map((source, _) => source.TheDog).OnTo(dest => dest.PetNames); This would reuse your Cheers. |
Hello again!
I'm going to include the Thanks again for the feedback - stay safe! Steve |
* Basic sequential data source support, re: issue #184 * Erroring if duplicate sequential data sources are configured * Extra test coverage * Erroring if sequential data source configured for simple type members * Extra test coverage * Erroring if configured data sources conflict with ignored source members * Start of API update * Updating sequential data source API * Support for conditional sequential data sources * Extra test coverage * Extending test coverage * Adding documentation * Extra test coverage * Start of sequential data sources for ctor parameters / Properly using fallback values in more places / Fixing tests * Moving map methods back into interface to fix test overload resolution?! * Fixing data source conflict tests * Removing sequential ctor data source test * Updating to v1.7-preview1
Sequential data source configuration is included in v1.7-preview1, which is now available on NuGet. mapper.WhenMapping
.From<SourceClass>().ToANew<DestinationClass>()
.Map((source, _) => source.TheCat)
.Then((source, _) => source.TheDog)
.To(dest => dest.PetNames); Cheers! |
* Optimising for loops! * Tidying * Organising enumerable mapping classes * Tidying enumerable mapping code * Fixing struct method creation factory caching * Updating projects to .NET Core project format / Tidying * Converting remaining projects to .NET Core project format, removing common AssemblyInfo files * Adding more-efficient FilterToArray method * Organising classes * Adding .NET 3.5 'hint path' * Using Environment.NewLine in test * Updating NUnit version * Organising configuration classes * Updating .Net35 test project * Trying NUnit test discovery fix * Removing * Removing unused code * Updating to v1.7 * Features/map instances using (#192) * Initial test + implementation * Resetting implementation * Adding mapping factories * Continued * Support for custom, unconditional root mapping factories * Continued * Removing target null checking from nested access checks * Integrating configured mapping factories as part of alternate mappings in ComplexTypeMappingExpressionFactory * Support for custom mapping factories in derived collection elements / Erroring if custom factories have invalid return types * Extending test coverage * Test coverage for configured root element mapping factory * Support for unconditional configured enumerable mapping factories * Support for conditional configured root enumerable mapping * Extending test coverage * Incorrect mapping factory configuration test coverge / Updating documentation * Tidying * Support for configuring non-enumerable to enumerable mapping using MapInstancesUsing * Refactoring * Support for root configured non-enumerable to enumerable mapping * Extending test coverage * Updating documentation / Adding inline mapping factory tests * Support for configured non-enumerable to enumerable element mapping * Fixing Net35 build * Support for conditional configured non-enumerable to enumerable mapping (#193) * Support for conditional configured non-enumerable to enumerable mapping * Fixing tests * Tidying * Removing duplicate short-circuit returns * Extending test coverage * Bugs/173 dictionary values to target (#194), re: issue #173 * Splitting ToTarget DataSource tests into dedicated test class / Adding failing test to prove bug * Fixing Dictionary.Values to List ToTarget data source mapping * Adding .NET Core 3.1 test project + updating packages and framework runtimes * Fix for configured simple-to-complex array data sources * Simplifying 'invocation position' code * Setting ConfiguredLambdaInfo target value factory in ctor * Features/value injection (#195) * All tests passing using ValueInjectors! * Removing ParametersSwapper + tidying * Deferring creation of Create mapping data calls * Support for same-type enumerable-to-enumerable to-target data sources * Including configured ToTarget data sources in mapping plan validation, re: #184 * Tidying * Updating readme * Features/sequential data sources (#196) * Basic sequential data source support, re: issue #184 * Erroring if duplicate sequential data sources are configured * Extra test coverage * Erroring if sequential data source configured for simple type members * Extra test coverage * Erroring if configured data sources conflict with ignored source members * Start of API update * Updating sequential data source API * Support for conditional sequential data sources * Extra test coverage * Extending test coverage * Adding documentation * Extra test coverage * Start of sequential data sources for ctor parameters / Properly using fallback values in more places / Fixing tests * Moving map methods back into interface to fix test overload resolution?! * Fixing data source conflict tests * Removing sequential ctor data source test * Updating to v1.7-preview1 * Updating release notes, adding v1.7-preview1 NuGet package * Surfacing mapping plan Expressions / Updating to ReadableExpressions v2.4 * Adding icon files * Updating packages * Features/to target instead (#198) * Start of ToTargetInstead logic * Refactoring * Moar * Ensuring configured mappings include callbacks and exception handling * Extending ToTargetInstead test coverage / ToTargetInstead support with simple type members * ToTargetInstead support for factory Funcs * Extending test coverage * Extending test coverage * Erroring if simple ToTarget source configured for complex target * Conditional ToTargetInstead support for complex type enumerable elements * Tidying * Tidying * Extra test coverage * Updating documentation * Erroring with redundant ToTarget configurations * Updating .NET Core framework versions for AppVeyor * Adding Test framework reference for AppVeyor * Updating framework version for AppVeyor * Adding NuGet package v1.7
v1.7 is now available on NuGet. Thanks again! |
Hello,
AgileMapper has worked wonders for me when mapping a source to different destinations but now I am having trouble with the other way around.
I am trying to map two different source instances to two properties of a destination instance. Normally I would use
OnTo
but I am using theThrowIfAnyMappingPlanIsIncomplete
option and it seems like they are incompatible.Here is an example : https://dotnetfiddle.net/aVzwph
Is there a better way of doing this ?
The text was updated successfully, but these errors were encountered: