How to set command timeout in aspnetcore/entityframeworkcore

If you’re using the DI container to manage the DbContext (i.e. you’re adding the DbContext to the service collection), the command timeout can be specified in the options. In Startup.ConfigureServices: services.AddDbContext<YourDbContext>(options => options.UseSqlServer( this.Configuration.GetConnectionString(“YourConnectionString”), sqlServerOptions => sqlServerOptions.CommandTimeout(60)) );

How to update the model when using database first approach

You can re-scaffold the model by running the command that you originally ran with the -Force option added. That will result in the contents of the specified folder being over-written. Using the Package Manager Console example from the EF Core docs, the revised command becomes: Scaffold-DbContext “Server=(localdb)\v11.0;Database=Blogging;Trusted_Connection=True;” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force Alternatively, if you are … Read more

ASP – Core Migrate EF Core SQL DB on Startup

A note from documentation on the call to db.Database.EnsureCreated(): Note that this API does not use migrations to create the database. In addition, the database that is created cannot be later updated using migrations. If you are targeting a relational database and using migrations, you can use the DbContext.Database.Migrate() method to ensure the database is … Read more

How to mock an async repository with Entity Framework Core

Thanks to @Nkosi for pointing me to a link with an example of doing the same thing in EF 6: https://msdn.microsoft.com/en-us/library/dn314429.aspx. This didn’t work exactly as-is with EF Core, but I was able to start with it and make modifications to get it working. Below are the test classes that I created to “mock” IAsyncQueryProvider: … Read more

navigation property should be virtual – not required in ef core?

virtual was never required in EF. It was needed only if you want lazy loading support. Since Lazy loading is not yet supported by EF Core, currently virtual have no special meaning. It would when (and if) they add lazy loading support (there is a plan for doing so). Update: Starting with EF Core 2.1, … Read more

Entity framework EF.Functions.Like vs string.Contains

Like query supports wildcard characters and hence very useful compared to the string extension methods in some scenarios. For ex: If we were to search all the 4 lettered names with ‘ri’ as the middle characters we could do EF.Functions.Like(c.Name, “_ri_”); or to get all the customers from cities which start with vowels: var customers … Read more

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