[英]Inheritance Database in Entity Framework Core and ASP.NET Core MVC
I'm following this course MVC with Entity Framework Core我正在学习这门课程MVC with Entity Framework Core
The class diagram in this course is something like this: Class Diagram image本课程中的 class 图是这样的: Class 图图像
In inheritance part Inheritance Part , they create a new table Person
to store all the data for 2 models Student
and Instructor
in Entity Framework.在 inheritance 部分Inheritance 部分中,他们创建了一个新表Person
来存储实体框架中 2 个模型Student
和Instructor
的所有数据。 And also drop 2 tables Student
and Instructor
in the database.并在数据库中删除 2 个表Student
和Instructor
。
Now, there are 3 models in Entity Framework: Person
, Student
, Instructor
现在,实体框架中有 3 个模型: Person
、 Student
、 Instructor
I try to get data into Student
and Instructor
models without loading Person
by我尝试在不加载Person
的情况下将数据导入Student
和Instructor
模型
modelBuilder.Entity<Person>().ToTable("Person");
and I get this message:我收到这条消息:
Code:代码:
public DbSet<Student> Students { get; set; }
public DbSet<Instructor> Instructors { get; set; }
private DbSet<Person> People { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Student>().ToTable("Person");
modelBuilder.Entity<Instructor>().ToTable("Person");
}
Questions问题
1. Does it mean all the data must be get into Entity Framework? 1.是不是所有的数据都必须进入Entity Framework?
2. In situation, for sensitive data is there any kind of pattern to make inheritance database? 2.在这种情况下,对于敏感数据,是否有任何一种模式来制作 inheritance 数据库?
Thanks a lot.非常感谢。
Now, there are 3 models in Entity Framework: Person, Student, Instructor现在,Entity Framework 中有 3 个模型:Person、Student、Instructor
If you don't have a use case that requires it, don't make Person an Entity.如果您没有需要它的用例,请不要将 Person 设为实体。 Just Student and Instructor.只是学生和导师。 Then you won't have any inheritance in the database.那么数据库中就不会有任何 inheritance 了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.