/// <summary> /// Gets an attached entity from the ID of a detached entity /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="entity"></param> /// <returns></returns> public static T GetAttachedEntity <T>(this IMyDbContext context, T entity) where T : class, IEntity { if (entity == null) { return(null); } return(context.GetLocal(entity) ?? context.Set <T>().FirstOrDefault(x => x.ID == entity.ID)); }