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

Set current/original values directly from dictionary #6368

Closed
ajcvickers opened this issue Aug 19, 2016 · 0 comments
Closed

Set current/original values directly from dictionary #6368

ajcvickers opened this issue Aug 19, 2016 · 0 comments
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@ajcvickers
Copy link
Contributor

Currently original/current values can be set from an object (entity or DTO) or from another PropertyValues object (e.g. set OriginalValues to CurrentValues).

@AndriySvyryd Suggested it would be good to be able to set from an IDictionary<string, object>.

This is the code you would write today to do this:

var currentValues = context.Entry(building).CurrentValues;
foreach (var property in currentValues.Properties)
{
    currentValues[property] = dictionary[property.Name];
}

Or if some properties may not be in the dictionary (e.g. shadow properties):

var currentValues = context.Entry(building).CurrentValues;
foreach (var keyValue in dictionary)
{
    currentValues[keyValue.Key] = keyValue.Value;
}

With the suggested API the code would be:

context.Entry(building).CurrentValues.SetValues(dictionary);
@divega divega added this to the 1.1.0 milestone Aug 19, 2016
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 22, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
@ajcvickers ajcvickers removed their assignment Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

2 participants