NSubstitute DbSet / IQueryable

This happens because of NSubstitute syntax specific. For example in: ((IQueryable<Blog>) mockSet).Provider.Returns(data.Provider); NSubstitute calls the Provider’s getter, then it specifies the return value. This getter call isn’t intercepted by the substitute and you get an exception. It happens because of explicit implementation of IQueryable.Provider property in DbQuery class. You can explicitly create substitutes for multiple … Read more

How to extend DbContext with partial class and partial OnModelCreating method in EntityFramework Core

EFCore 3 – They FINALLY fixed this! You can now implement OnModelCreatingPartial in a partial class like this. Note the partial keyword on both the class and method: public partial class RRStoreContext : DbContext { partial void OnModelCreatingPartial(ModelBuilder builder) { builder.Entity<RepeatOrderSummaryView>().HasNoKey(); } } If you look at the generated context file – right at the … Read more

DbContext is very slow when adding and deleting

Try to add this to your DbContext tests: dbContext.Configuration.AutoDetectChangesEnabled = false; // Now do all your changes dbContext.ChangeTracker.DetectChanges(); dbContext.SaveChanges(); and try to run your tests again. There was some architectural change in DbContext API which checks changes in entities every time you Add, Attach or Delete anything from the context. In ObjectContext API this detection … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)