Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update only changed columns
Message
Information générale
Forum:
C#
Catégorie:
Entity Framework
Divers
Thread ID:
01657108
Message ID:
01657198
Vues:
75
This message has been marked as a message which has helped to the initial question of the thread.
You can retrieve and EnityEntry and on that object you can find the modification state. When you attach entities they are considered all changed and that's why you see this. If you just load and then save with changes only the changes are updated.

Here's a link from Westwind.Data (which is a simple EF business wrapper) to DbEntityEntry. From there you can set the modification state for the entire entity and also look at the current values and their change state.

https://github.com/RickStrahl/WestwindToolkit/blob/master/Westwind.Data/EfCodeFirst/EfCodeFirstBusinessBase.cs#L1170


+++ Rick ---


>Hi everybody,
>
>I discovered that for our many columns single row tables all columns are getting updated causing the problems. I'm wondering how can EF update only columns that were changed?
>
>I found this blog post https://dotnettips.wordpress.com/2009/10/28/retrieving-changed-properties-from-the-entity-framework/ but it's a bit complex for me, not sure how to apply to our code.
>
>Our code basically sends viewModel (that may have less columns than the table) to the server, maps viewModel back to the entity class using AutoMapper and then updates the table using repository code
>
>
>  EntityState entityState = _siriusContext.GetEntityState(entity);
>                if (entityState == EntityState.Detached)
>                {
>                    _dbSetList.Attach(entity);
>                    _siriusContext.SetModified(entity);
>                }
>
>                SaveChanges();
>
>
>This code leads to every single column being updated in the table.
>
>I found this blog https://dotnettips.wordpress.com/2009/10/28/retrieving-changed-properties-from-the-entity-framework/
>
>but it's not clear how to incorporate it (if possible) in our code.
>
>What are possible solutions for the problem? Is there a simple way to only update changed columns?
>
>Thanks a lot in advance.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform