Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return descriptions to the interface
Message
 
 
À
27/10/2015 17:31:47
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:
01626353
Message ID:
01626530
Vues:
28
I implemented the following in the repository for that class and it seems to work well (in a couple of tests I've tried):
public void Update(SChannels entity, List<ScsgLink> deletedLinks)
        {
            try
            {
                EntityState entityState = _siriusContext.GetEntityState(entity);
                if (entityState == EntityState.Detached)
                {
                    _dbSet.Attach(entity);
                    _siriusContext.SetModified(entity);
                    foreach(ScsgLink link in deletedLinks)
                    {
                        _siriusContext.SetDeleted(link);
                    }

                    foreach(ScsgLink link in entity.ScsgLink.Where(s=>s.Added==true))
                    {
                        _siriusContext.SetAdd(link);
                    }
                }

                SaveChanges();
            }
            //catch (DbEntityValidationException dbex)
            //{
            //    var msg = dbex.EntityValidationErrors.ToList();
            //}
            catch (DbUpdateException ex)
            {
                ThrowError(ex);
            }           
        }
I had to add a new NotMapped Added property and a DeletedLinks to the ViewModel and make all necessary changes. So, this is not generic enough, but I'm not sure how to make the above more generic.
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform