Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return descriptions to the interface
Message
 
 
To
27/10/2015 17:31:47
General information
Forum:
ASP.NET
Category:
Entity Framework
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01626353
Message ID:
01626530
Views:
30
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
Previous
Reply
Map
View

Click here to load this message in the networking platform