当前位置:网站首页>[C] overide can override the virtual method inherited from a higher parent
[C] overide can override the virtual method inherited from a higher parent
2022-06-10 22:10:00 【I left my life to work】
Inheritance relationships
Three class:
- public class DbContext
- public abstract class
- public class BaseContext
among :
BaseContext : BasicDbContext
BasicDbContext : DbContext
Related methods in three classes
DbContext
//
// Abstract :
// Override this method to further configure the model that was discovered by convention
// from the entity types exposed in Microsoft.EntityFrameworkCore.DbSet`1 properties
// on your derived context. The resulting model may be cached and re-used for subsequent
// instances of your derived context.
//
// Parameters :
// modelBuilder:
// The builder being used to construct the model for this context. Databases (and
// other extensions) typically define extension methods on this object that allow
// you to configure aspects of the model that are specific to a given database.
//
// speech :
// If a model is explicitly set on the options for this context (via Microsoft.EntityFrameworkCore.DbContextOptionsBuilder.UseModel(Microsoft.EntityFrameworkCore.Metadata.IModel))
// then this method will not be run.
protected internal virtual void OnModelCreating(ModelBuilder modelBuilder)
{
}
BasicDbContext
protected void OnModelCreating(ModelBuilder modelBuilder, Type type)
{
Code omitted here ...
base.OnModelCreating(modelBuilder);
}
}
BaseContext
This method overrides OnModelCreating There is only one parameter , That is, the overridden method comes from the parent BasicDbContext The father of DbContext, In order to verify , hold BasicDbContext Of OnModelCreating After the method is renamed , The compiler does not prompt for errors .
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder, typeof(BaseEntity));
foreach (var entityType in modelBuilder.Model.GetEntityTypes().Where(e => typeof(BaseEntity).IsAssignableFrom(e.ClrType)))
{
modelBuilder.Entity(entityType.ClrType).Property<int>("IsDeleted");
var parameter = Expression.Parameter(entityType.ClrType, "e");
var body = Expression.Equal(
Expression.Call(typeof(EF), nameof(EF.Property), new[] {
typeof(int) }, parameter, Expression.Constant("IsDeleted")),
Expression.Constant(0));
modelBuilder.Entity(entityType.ClrType).HasQueryFilter(Expression.Lambda(body, parameter));
}
}
expand
EF Core Ignore global filter references :
【.Net Core】EntityFramework Core Global filtering (HasQueryFilter)
边栏推荐
- Principle of gravure overprint and factors affecting overprint
- Interview Essentials - basic knowledge of synchronized underlying principles
- 数组 移动0
- 初中毕业生,选择中职学校也可以升入高等学府
- 用少儿编程思维塑造青少年领悟能力
- 【MySQL】表的约束
- [nk] 牛客月赛51 G计算题
- Extracting Nalu unit data from H264 real-time stream
- Junior high school graduates who choose secondary vocational schools can also be promoted to institutions of higher learning
- 【MySQL】表数据的增删查改(DML)
猜你喜欢
![[nk] 牛客月赛51 F-平均题](/img/b3/c36a0032e606f38fdc2f7c4562713c.png)
[nk] 牛客月赛51 F-平均题
An analysis of SQL query optimization principle (900w+ data from 17s to 300ms)
![[1024 ways to play windows azure] 75 Fast cloud database migration seamlessly migrate alicloud RDS SQL server to azure SQL databas](/img/00/798455f2db289e3aaed36981ea1e7c.png)
[1024 ways to play windows azure] 75 Fast cloud database migration seamlessly migrate alicloud RDS SQL server to azure SQL databas
![[nk] Niuke monthly competition 51 f-average question](/img/b3/c36a0032e606f38fdc2f7c4562713c.png)
[nk] Niuke monthly competition 51 f-average question

学IT毕业后该去哪个城市?哪个岗位薪资高?哪些公司待遇好?

构建幼儿Steam教育实施策略
Detailed steps and actual records of SQL server2019 installation (available for hands-on test)

2022-06-09 RK817 PMU 電池溫度檢測

C language ---5 initial string, escape character and comment

2022-06-09 RK817 PMU 电池温度检测
随机推荐
Mysql之将查询结果插入到其它表中
The process of keyword search in Oracle tables
Apple zoom! It's done so well
系统重装以及查询系统性能
19 MySQL optimizations commonly used in projects
数组 是否存在重复元素
在Oracle表中进行关键词搜索的过程
【北大青鸟昌平校区】职教与普教协调发展,今年的中考会容易吗?
C language -- 7 operators
[nk] Niuke monthly race 51g calculation problem
[nk] 牛客月赛51 G计算题
How to realize the marketing purpose of small program integral mall
Business based precipitation component = & gt; manage-table
php的exec函数
【生成对抗网络学习 其一】经典GAN与其存在的问题和相关改进
Tableau auto - fabriqué
A WPF developed Print dialog box -printdialogx
C language -- 8 familiar keywords
Extracting Nalu unit data from H264 real-time stream
数组 加一