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

How to handle two objs of the same type in the EntityMapper #2

Closed
iamgmd opened this issue Feb 10, 2018 · 7 comments
Closed

How to handle two objs of the same type in the EntityMapper #2

iamgmd opened this issue Feb 10, 2018 · 7 comments
Assignees
Milestone

Comments

@iamgmd
Copy link

iamgmd commented Feb 10, 2018

I am having trouble when trying to map two of the same model type in my entity mapper. Is there a way to handle this?

Model

public class Account
{
public Guid AccountId { get; set; }
public string Name { get; set; }
public Contact PrimaryContact { get; set; }
public Contact SecondaryContact { get; set; }
}

EntityMapper

public class AccountEntityMapper :
IEntityMapper
{
public Func<Account, Account> ResolveEntity { get; set; }
public Account Map(IEnumerable objs)
{
Account account = null;
foreach (var obj in objs)
{
if (obj is Account p)
{
account = ResolveEntity(p);
continue;
}
if (obj is Contact primaryContact)
{
account.PrimaryContact = primaryContact;
continue;
}
if (obj is Contact secondaryContact)
{
account.SecondaryContact = secondaryContact;
continue;
}
}
return account;
}
}

@dougrday
Copy link
Member

I'm working on a solution to this with code examples, it would require an upgrade to a later version.

Stay tuned.

@iamgmd
Copy link
Author

iamgmd commented Feb 19, 2018

Excellent dougrday, looking forward to it.

@iamgmd
Copy link
Author

iamgmd commented Mar 12, 2018

Hi dougrday, any news on this implementation? it's currently a blocker for my project.

@dougrday
Copy link
Member

I'll see if I can get the implementation pushed up to github in the next couple of days, with code examples. I'm having trouble getting SQLite to play nice with it (the in-memory implementation doesn't appear to support this kind of situation), but other providers should work.

@dougrday dougrday self-assigned this Mar 16, 2018
@dougrday dougrday modified the milestones: 0.1.1, 0.2.0 Mar 16, 2018
@dougrday
Copy link
Member

dougrday commented Mar 16, 2018

This has been added in release 0.2.0-beta, and is available on NuGet. Sorry for the wait.

dougrday added a commit that referenced this issue Mar 16, 2018
@dougrday
Copy link
Member

dougrday commented Mar 16, 2018

@iamgmd You should be unblocked, please let me know if the implementation doesn't provide the functionality you need. See here for examples:

PersonType.cs (line 47) - see "supervisor" and "careerCounselor" types.
PersonQueryBuilder.cs (line 55)
PersonQuery.cs (line 29)
PersonEntityMapper.cs (line 44)

@iamgmd
Copy link
Author

iamgmd commented May 15, 2018

@dougrday Works great, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants