EntityFramework Code First – Check if Entity is attached
You can find the answer here. public bool Exists<T>(T entity) where T : class { return this.Set<T>().Local.Any(e => e == entity); } Place that code into your context or you can turn it into an extension like so. public static bool Exists<TContext, TEntity>(this TContext context, TEntity entity) where TContext : DbContext where TEntity : class … Read more