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);
}