/// <summary>
        /// Base Method for Updating an Item in the DB Context.
        /// </summary>
        /// <typeparam name="TEntity">Type Parameter</typeparam>
        /// <param name="entity">Entity to Update</param>
        /// <returns>Resulting Entity</returns>
        protected virtual TEntity Update <TEntity>(TEntity entity) where TEntity : class
        {
            var           entry     = ctx.Entry(entity);
            IKey          key       = entry.Metadata.FindPrimaryKey();
            List <object> keyValues = new List <object>();

            foreach (IProperty prop in key.Properties)
            {
                PropertyInfo pi = prop.PropertyInfo;
                keyValues.Add(pi.GetValue(entity));
            }

            var original = ctx.Find <TEntity>(keyValues.ToArray());

            if (!entity.Equals(original))
            {
                ctx.Entry(original).CurrentValues.SetValues(entity);
            }
            ctx.SaveChanges();
            return(ctx.Entry(entity).Entity);
        }