Skip to content
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

Mapping more that two objects into one #389

Closed
philn5d opened this issue Sep 20, 2013 · 5 comments
Closed

Mapping more that two objects into one #389

philn5d opened this issue Sep 20, 2013 · 5 comments

Comments

@philn5d
Copy link

philn5d commented Sep 20, 2013

Looking to map two+ objects into one object.

loose example:

class Person
{
public string Name { get; set; }
public string Age { get; set; }
}
class ClassRoom
{
public int RoomNumber { get; set; }
}

class PersonClassViewModel
{
public string Name { get; set; }
public string Age { get; set; }
public int RoomNumber { get; set; }
}
.
.
.

var vm = Mapper.Map(person, classRoom);

.
.
.

@jbogard
Copy link
Member

jbogard commented Sep 22, 2013

You can do this, but configuration validation won't work. It doesn't know that you'll be using 2 things to map into 1. That's pretty much the reason why I never implemented this, you can't test your mappings at that point.

@jbogard jbogard closed this as completed Sep 22, 2013
@philn5d
Copy link
Author

philn5d commented Sep 23, 2013

Thanks for the info. I am doing this in this way:

CreateMap<Things1, Thingamajigger>()
.ForMember(d=>d.Things2Property, s=>s.Ignore());
.
similar for Things2
.
.

Thingamajigger trouble = Mapper.Map(thing1);

trouble = Mapper.Map(thing2, trouble);

I may have juxtaposed the last 2 since I'm not looking at any code or documentation right now. This seems to be working. Is this best practice for this?

Thank you,

Phil Vuollet


From: Jimmy Bogardmailto:notifications@github.com
Sent: ‎9/‎22/‎2013 3:59 PM
To: AutoMapper/AutoMappermailto:AutoMapper@noreply.github.com
Cc: philn5dmailto:themadgeneral@hotmail.com
Subject: Re: [AutoMapper] Mapping more that two objects into one (#389)

You can do this, but configuration validation won't work. It doesn't know that you'll be using 2 things to map into 1. That's pretty much the reason why I never implemented this, you can't test your mappings at that point.


Reply to this email directly or view it on GitHub:
#389 (comment)

@jbogard
Copy link
Member

jbogard commented Sep 23, 2013

What I usually do is create a composite object on the source side first,
and then map that over. That seems to be easier than trying to mash two
objects together that may not line up. Also, that way I don't have Ignores
around.

On Mon, Sep 23, 2013 at 9:54 AM, philn5d notifications@github.com wrote:

Thanks for the info. I am doing this in this way:

CreateMap<Things1, Thingamajigger>()
.ForMember(d=>d.Things2Property, s=>s.Ignore());
.
similar for Things2
.
.

Thingamajigger trouble = Mapper.Map(thing1);

trouble = Mapper.Map(thing2, trouble);

I may have juxtaposed the last 2 since I'm not looking at any code or
documentation right now. This seems to be working. Is this best practice
for this?

Thank you,

Phil Vuollet


From: Jimmy Bogardmailto:notifications@github.com
Sent: 9/22/2013 3:59 PM
To: AutoMapper/AutoMappermailto:AutoMapper@noreply.github.com
Cc: philn5dmailto:themadgeneral@hotmail.com
Subject: Re: [AutoMapper] Mapping more that two objects into one (#389)

You can do this, but configuration validation won't work. It doesn't know
that you'll be using 2 things to map into 1. That's pretty much the reason
why I never implemented this, you can't test your mappings at that point.


Reply to this email directly or view it on GitHub:
#389 (comment)


Reply to this email directly or view it on GitHubhttps://github.com//issues/389#issuecomment-24925795
.

@philn5d
Copy link
Author

philn5d commented Sep 23, 2013

This is a little bit of an odd case where we are populating something like a view model (but a flat one) since the consumer does not work well with collections as properties. So we are mapping from 2 source services into one flat view model in an adapter/controller service for the presentation layer.

In the previous example, Thingamajigger is a flattened version of Thing1 and Thing2 that exposes all properties of both in one class.

Phil Vuollet


From: Jimmy Bogardmailto:notifications@github.com
Sent: ‎9/‎23/‎2013 10:39 AM
To: AutoMapper/AutoMappermailto:AutoMapper@noreply.github.com
Cc: philn5dmailto:themadgeneral@hotmail.com
Subject: Re: [AutoMapper] Mapping more that two objects into one (#389)

What I usually do is create a composite object on the source side first,
and then map that over. That seems to be easier than trying to mash two
objects together that may not line up. Also, that way I don't have Ignores
around.

On Mon, Sep 23, 2013 at 9:54 AM, philn5d notifications@github.com wrote:

Thanks for the info. I am doing this in this way:

CreateMap<Things1, Thingamajigger>()
.ForMember(d=>d.Things2Property, s=>s.Ignore());
.
similar for Things2
.
.

Thingamajigger trouble = Mapper.Map(thing1);

trouble = Mapper.Map(thing2, trouble);

I may have juxtaposed the last 2 since I'm not looking at any code or
documentation right now. This seems to be working. Is this best practice
for this?

Thank you,

Phil Vuollet


From: Jimmy Bogardmailto:notifications@github.com
Sent: 9/22/2013 3:59 PM
To: AutoMapper/AutoMappermailto:AutoMapper@noreply.github.com
Cc: philn5dmailto:themadgeneral@hotmail.com
Subject: Re: [AutoMapper] Mapping more that two objects into one (#389)

You can do this, but configuration validation won't work. It doesn't know
that you'll be using 2 things to map into 1. That's pretty much the reason
why I never implemented this, you can't test your mappings at that point.


Reply to this email directly or view it on GitHub:
#389 (comment)


Reply to this email directly or view it on GitHubhttps://github.com//issues/389#issuecomment-24925795
.


Reply to this email directly or view it on GitHub:
#389 (comment)

@lock
Copy link

lock bot commented May 8, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants