예제 #1
0
        /// <summary>
        /// Changes the state of an entity entry when requested state differs.
        /// </summary>
        /// <param name="entry">The entry instance</param>
        /// <param name="requestedState">The requested new state</param>
        /// <returns><c>true</c> if the state has been changed, <c>false</c> if current state did not differ from <paramref name="requestedState"/>.</returns>
        public static bool TryChangeState(this EntityEntry entry, EfState requestedState)
        {
            if (entry.State != requestedState)
            {
                // Only change state when requested state differs,
                // because EF internally sets all properties to modified
                // if necessary, even when requested state equals current state.
                entry.State = requestedState;

                return(true);
            }

            return(false);
        }
예제 #2
0
 public void Attach(Microsoft.EntityFrameworkCore.EntityState state, Artist artist)
 {
     _context.Attach(artist).State = state;
 }