Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating multiple rows with EF
Message
 
 
À
29/04/2015 17:42:35
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01619231
Message ID:
01619239
Vues:
35
>>Hi everybody,
>>
>>I did a quick research in Google and found that if we want to update multiple rows, we would need to loop through each row and update separately. I just want to make sure it's true and this is what I need.
>
>If I understand correctly, if there are 100 items in your collection, this will fire 100 UPDATE statements back to the database. Am I correct?

Yes but in one transaction if we put SaveChanges at the end.

In any case, I found that it's not working for me as is right now. I have a view which is based on a single table. I didn't add with schemabinding, may be if I add this, it'll help. I also added INSTEAD OF UPDATE trigger for that view. I didn't have a chance yet to test if anything is going on when I issue the SaveChanges method. But I noticed that in the configuration file that was auto-generated by Reverse POCO generator every single column is listed as a key. I think this may be part of a problem and it will probably be resolved if I add schemabinding.

BTW, while I am at this. In our code in the update method (which was originally for a single row) we just use this code:
try
            {
                EntityState entityState = _siriusContext.GetEntityState(entity);
                if (entityState == EntityState.Detached)
                {
                    _dbSetList.Attach(entity);
                }
                if (_siriusContext != null)
                    _siriusContext.SetModified(entity);

                SaveChanges();
So, we always just set the Modified state manually. In my case when I send the list, I'd rather set only changed rows that state. Is there a method that will check for actual changes? I assume there should be one and EF is supposed to be working OK for a view.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform