-
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
Configuring null foreign keys not to be mapped to corresponding object property #121
Comments
I was able to bypass the new object creation by using IgnoreEntityKeys:
Unfortunately, this also ignores the primary key Id field from the original DTO and Entity Framework Core then thinks it is a new object. |
Hi John! Hmm - that's certainly not the intended behaviour - I'll take a look and sort it out. In the meantime, you can work around it using: Mapper.WhenMapping
.ToANew<Pet>()
.If((o, p) => string.IsNullOrEmpty(p.Name))
.MapToNull(); I've put together a fiddle showing this at work :) Cheers, Steve |
…ted member is an identifier, and it isn't given a non-default value. Fixes #121.
This is fixed in the latest code - if the only member of a complex type member mapped during a mapping is an identifier, and it isn't given a non-default value, the complex type member isn't populated. If non-identifier members are included in the mapping - like if Release to follow. Thanks for the feedback! :) |
This is fixed as of v1.3-preview2. |
Given I have four classes defined as:
And I map a PersonDto to a Person:
The resulting object is:
Even though PetId is null in the original PersonDto, AgileMapper creates a new empty Pet anyway. The issue is that Entity Framework Core sees these as newly added objects and will add them to a database, even though pet is optional for a person.
Is there a way to turn this behavior off in AgileMapper so that if a "foreign key" in an object is null (or 0), do not instantiate a new object for the matching object property?
The text was updated successfully, but these errors were encountered: