9.5 KiB
Pf2eModel
Pf2eModel
Pf2eDbContext Class
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 class Pf2eDbContext : Microsoft.EntityFrameworkCore.DbContext
Inheritance System.Object 🡒 Microsoft.EntityFrameworkCore.DbContext 🡒 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.
| Constructors | |
|---|---|
| Pf2eDbContext() | Инициализирует новый экземпляр класса Pf2eDbContext без параметров. |
| Pf2eDbContext(DbContextOptions<Pf2eDbContext>) | Инициализирует новый экземпляр класса Pf2eDbContext с указанными параметрами конфигурации базы данных. |
| Fields | |
|---|---|
| NameLength | Длина названия сущности. |
| Methods | |
|---|---|
| BindEntity<T>(EntityTypeBuilder<T>) | Устанавливает связь между сущностью и её корневой сущностью. |
| BindLocaleString<T>(EntityTypeBuilder<T>, Expression<Func<T,LocaleString>>, bool) | Устанавливает связь между сущностью и локализованной строкой. |
| DefineBase(ModelBuilder) | Определяет базовые сущности и их связи. |
| DefineCommon(ModelBuilder) | Определяет общие сущности и их связи. |
| DefineMethods(ModelBuilder) | Определяет методы, которые будут использоваться в запросах LINQ. |
| DefineStructure(ModelBuilder) | Определяет структуру сущностей и их связи. |
| LocaleSearch(LocaleString, string) | CLR-представление функции поиска в локализованной строке. |
| LocaleSearchArray(LocaleString, IEnumerable<string>) | CLR-представление функции поиска в локализованной строке с массивом значений для поиска. |
| OnConfiguring(DbContextOptionsBuilder) | Override this method to configure the database (and other options) to be used for this context. This method is called for each instance of the context that is created. The base implementation does nothing. |
| OnModelCreating(ModelBuilder) | Override this method to further configure the model that was discovered by convention from the entity types exposed in Microsoft.EntityFrameworkCore.DbSet<> properties on your derived context. The resulting model may be cached and re-used for subsequent instances of your derived context. |