-
Notifications
You must be signed in to change notification settings - Fork 50
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
Comments
I'm working on a solution to this with code examples, it would require an upgrade to a later version. Stay tuned. |
Excellent dougrday, looking forward to it. |
Hi dougrday, any news on this implementation? it's currently a blocker for my project. |
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. |
This has been added in release 0.2.0-beta, and is available on NuGet. Sorry for the wait. |
@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. |
@dougrday Works great, thanks. |
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;
}
}
The text was updated successfully, but these errors were encountered: