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

ExtraProperties Can Not be updated #772

Closed
goxiaoy opened this issue Jan 30, 2019 · 6 comments
Closed

ExtraProperties Can Not be updated #772

goxiaoy opened this issue Jan 30, 2019 · 6 comments

Comments

@goxiaoy
Copy link
Contributor

goxiaoy commented Jan 30, 2019

EF Core ConfigureExtraProperties use Value Conversions to convert Dictionary to string colum. But if we directly set key-value in entity.ExtraProperties, ef cannot detect property change during update

@goxiaoy goxiaoy changed the title ExtraProperties Can Not been update ExtraProperties Can Not be updated Jan 30, 2019
@hikalkan
Copy link
Member

hikalkan commented Feb 4, 2019

Hmmm.. didn't know that. Should be tested. Thank you for informing.

@hikalkan hikalkan modified the milestones: Backlog, 0.14 Feb 4, 2019
@hikalkan
Copy link
Member

I added integration tests (works with inmemory SQLite) and it seems working: d07a689#diff-19dff7480171145bae8f3387b91a5059

Did you try it yourself? If so, we will also try with a real application.

@hikalkan hikalkan removed this from the 0.14 milestone Feb 19, 2019
@goxiaoy
Copy link
Contributor Author

goxiaoy commented Feb 20, 2019

I have tested with MySQL and failed.

For temporary solution, I have to added code below in every extra entity to fix that.

        public void UpdateExtra(string key, object value)
        {
            var newDic = new Dictionary<string, object>(ExtraProperties);
            newDic[key] = value;
            ExtraProperties = newDic;
        }

And I can not write an extension function for IHasExtraProperties cause ExtraProperties have no setter

@acjh
Copy link
Contributor

acjh commented Feb 20, 2019

One important thing I have noticed, however, is that when updating the entity and changing items in the dictionary, the EF change tracking does not pick up on the fact that the dictionary was updated, so you will need to explicitly call the Update method ... to set the entity to modified in the change tracker.

https://www.jerriepelser.com/blog/store-dictionary-as-json-using-ef-core-21/

@hikalkan
Copy link
Member

hikalkan commented Feb 20, 2019

Good point @acjh that means repository.Update (or UpdateAsync) method should always be called. Actually, this is a best practice that we suggest with this ABP framework. All the pre-built modules do it (because some database APIs has no change tracking, like MongoDB driver).

Creating a new dictionary for each change is not efficient and seems bad to me.

@stale
Copy link

stale bot commented Jul 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

3 participants