That discover types that implement the interface. How arguments can be passed to this method via the various design-time tools Parameter on the CreateDbContext method is not currently It should be noted at this stage that the string args Return new SampleContext(optionsBuilder.Options) įinally, you must ensure that your context has a constructor that takes aĭbContextOptions object as a parameter: public SampleContext(DbContextOptions options) : base (options) Opts => opts.CommandTimeout(( int )TimeSpan.FromMinutes(10).TotalSeconds) Public SampleContext CreateDbContext( string args) Specified for the runtime version of the context: public class SampleContextFactory : IDesignTimeDbContextFactory Minutes, as opposed to the default 30 seconds, or whatever value has been for example to set the timeout for 2 hours : Source Oracle. Override the creation of SampleContext, specifying a command timeout value of 10 Similar to the ODBC timeout configuration there is also a timeout setting for an Oracle connection (with slightly different syntax). The following example illustrates the use of IDesignTimeDbContextFactory to As such, it provides a hook for overriding the construction of You to configure the context in a different manner to the way it is configuredįor runtime use. If one exists, it is instantiated and its CreateDbContext method is called which returns the derived The tools are configured to search the assembly containing theĭbContext (or the one designated as the startup assembly) for a type that This interface is only intended for use with design time tools such as This (and other) problems associated with configuring DbContext objectsĭifferently for certain design-time tasks, such as migrations. The IDesignTimeDbContextFactory was introduced in EF Core 2.0 to alleviate Prior to version 2.0 of EF Core, your options were limited to changing the command timeout for the DbContext, running the migration and then resetting the timeout value (or not): public SampleContext()ĭatabase.SetCommandTimeout(( int )TimeSpan.FromMinutes(5).TotalSeconds)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |