Files
Pf2eDataScrapper/Documentation/Pf2e.Scrapper/FoundryEnAbstractProcessor_TEntity_.Context.md
2025-10-04 22:52:22 +04:00

5.0 KiB

Pf2e.Scrapper

Pf2e.Scrapper.Importers.Implementations.FoundryEn.Processors.FoundryEnAbstractProcessor<TEntity>

FoundryEnAbstractProcessor<TEntity>.Context Property

A DbContext instance represents a session with the database and can be used to query and save instances of your entities. DbContext is a combination of the Unit Of Work and Repository patterns.

public Pf2e.Database.Pf2eDbContext Context { get; }

Property Value

Pf2e.Database.Pf2eDbContext

Remarks

Entity Framework Core does not support multiple parallel operations being run on the same DbContext instance. This includes both parallel execution of async queries and any explicit concurrent use from multiple threads. Therefore, always await async calls immediately, or use separate DbContext instances for operations that execute in parallel. See Avoiding DbContext threading issues for more information and examples.

Typically you create a class that derives from DbContext and contains Microsoft.EntityFrameworkCore.DbSet<> properties for each entity in the model. If the Microsoft.EntityFrameworkCore.DbSet<> properties have a public setter, they are automatically initialized when the instance of the derived context is created.

Override the Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder) method to configure the database (and other options) to be used for the context. Alternatively, if you would rather perform configuration externally instead of inline in your context, you can use Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<> (or Microsoft.EntityFrameworkCore.DbContextOptionsBuilder) to externally create an instance of Microsoft.EntityFrameworkCore.DbContextOptions<> (or Microsoft.EntityFrameworkCore.DbContextOptions) and pass it to a base constructor of Microsoft.EntityFrameworkCore.DbContext.

The model is discovered by running a set of conventions over the entity classes found in the Microsoft.EntityFrameworkCore.DbSet<> properties on the derived context. To further configure the model that is discovered by convention, you can override the Microsoft.EntityFrameworkCore.DbContext.OnModelCreating(Microsoft.EntityFrameworkCore.ModelBuilder) method.

See DbContext lifetime, configuration, and initialization, Querying data with EF Core, Changing tracking, and Saving data with EF Core for more information and examples.