Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating multiple rows with EF
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Titre:
Updating multiple rows with EF
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:
01619231
Vues:
39
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.

I have the following base class method
public virtual void Update(T entity)
        {
            try
            {
                EntityState entityState = _siriusContext.GetEntityState(entity);
                if (entityState == EntityState.Detached)
                {
                    _dbSet.Attach(entity);
                }
                if (_siriusContext != null)
                    _siriusContext.SetModified(entity);

                SaveChanges();
            }
            catch (DbEntityValidationException dbex)
            {
                var msg = dbex.EntityValidationErrors.ToList();
            }
            catch (DbUpdateException ex)
            {
                _exceptionParser.ThrowUniqueConstraintException(ex);
            }

            catch (AmbiguousMatchException ex)
            {
                Log.Error("Ambiguous Match Exception", ex);
                throw ex;
            }
        }
for a one row update. Now I just want to use
public virtual void Update(List<T> entities)
So, would I need to add transactions here and loop through the list or there is a better method available?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform