简体   繁体   English

Entity Framework Core 和 ASP.NET Core MVC 中的 Inheritance 数据库

[英]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 个模型StudentInstructor的所有数据。 And also drop 2 tables Student and Instructor in the database.并在数据库中删除 2 个表StudentInstructor

Now, there are 3 models in Entity Framework: Person , Student , Instructor现在,实体框架中有 3 个模型: PersonStudentInstructor

I try to get data into Student and Instructor models without loading Person by我尝试在不加载Person的情况下将数据导入StudentInstructor模型

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.

相关问题 ASP.NET Core MVC +实体框架+ GET +数组 - ASP.NET Core MVC + Entity Framework + GET + Array ASP.NET MVC Core和Entity Framework中的ToListAsync无法正常工作 - ToListAsync in ASP.NET MVC Core and Entity Framework not working Asp.Net 核心 MVC 微软实体框架 - Asp.Net core MVC Microsoft Entity Framework ASP.NET Core MVC &amp; C#:使用实体框架将数据插入数据库 - ASP.NET Core MVC & C# : insert data into database using Entity Framework 如何将 email 列表从 ASP.NET Core MVC 中的数据库实体框架传递给 MailboxAddress - How to pass email list to MailboxAddress from database Entity Framework in ASP.NET Core MVC ASP.net Core Application Entity Framework 6无法生成数据库 - ASP.net Core Application Entity Framework 6 not generating database 使用实体框架在ASP.Net Core 2中动态创建数据库表 - Dynamic database table creation in ASP.Net Core 2 with Entity Framework 使用实体框架在 ASP.NET 核心中为 SQLite 数据库设置 DateTimeKind - Setting DateTimeKind for SQLite database in ASP.NET Core with Entity Framework 实体框架 6.3 与 ASP.NET 核心 3 - Entity Framework 6.3 with ASP.NET Core 3 在没有实体框架和迁移的ASP.NET Core MVC应用程序中使用ASP.NET标识 - Using ASP.NET Identity in an ASP.NET Core MVC application without Entity Framework and Migrations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM