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) is limiting the time of executing the SQL query (imagine some super complex SQL command with many joins, cartesian products, group by, subqueries etc. Public SampleContext CreateDbContext( string args) Command timeout is just for the ExecuteXYZ part of the database command, which for queries is ExecuteReader, i.e. 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 Override the creation of SampleContext, specifying a command timeout value of 10 The following example illustrates the use of IDesignTimeDbContextFactory to As such, it provides a hook for overriding the construction of The default value is null, where null indicates that the default value of the. You to configure the context in a different manner to the way it is configuredįor runtime use. Gets or sets the timeout value, in seconds, for all context operations. 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. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |