Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

EF core entity update

$
0
0

Is this a valid update method in repo pattern within EF core to update attached entities.

public virtual void Update(TEntity obj)
{
           DbSet.Update(obj);
            var attachedObj = DbSet.Local.FirstOrDefault(e => e.Id.Equals(obj.Id));
            if (attachedObj != null)
            {
                var attachedEntry = DbContext.Entry(attachedObj);
                attachedEntry.CurrentValues.SetValues(obj);
            }
            else
                DbSet.Update(obj);
         }


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>