需要帮助迁移现有模式,包括每个类型继承表 [英] Need help migrating existing model to include table per type inheritance

查看:133
本文介绍了需要帮助迁移现有模式,包括每个类型继承表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作的应用程序是用于跟踪客户信息(创建,查看,编辑)一个简单的应用程序。我想扩大应用程序能够以包括有关客户的家庭成员基本信息。

The application I'm working on is a simple application for keeping track of client information (creating, viewing, editing). I'd like to expand the application to be able to include basic information about family members of the clients.

我最近发现使用继承的实体框架,并想创建一个简单的继承层次结构,在这里客户从一个类叫做人继承,因为客户保持许多相同的信息,他们的家庭成员再加上一些额外的东西轨道的能力。这样,如果一个家庭成员也成为一个客户,他们将只需要在客户端表具有额外的信息对应的条目。

I recently discovered the ability to use inheritance in entity framework and would like to create a simple inheritance hierarchy where clients inherit from a class called person because clients keep track of much of the same information as their family members plus some extra stuff. This way, if a family member also became a client they would just need a corresponding entry in the client table with the extra info.

在哪里我卡是如何将现有的模型迁移到这种新模式。在该模型的变化似乎是清楚的,是这样的:

Where I'm stuck is how to migrate the existing model to this new model. The changes in the model seem clear, something like this:

public class Person
{
     public Int32 ClientID { get; set; }
     ... other fields ...
}

[Table("Client")]
public class Client : Person
{
    ... client specific fields ...
}

但需要什么样的变化,以进行上下文和其他地方成功地迁移到这种新模式?只是在做插件迁移的NuGet时作出上述改变对模型的空白迁移走了过来。

but what changes need to be made to the context and elsewhere to successfully migrate to this new model? Just making these changes to the model came up with a blank migration when doing add-migration in NuGet.

编辑:迁移不再是空白的,但增加了一个鉴别列我的理解是表的每个层级设置的一部分

The migration is no longer blank but adds a discriminator column which I understand is a part of table per hierarchy setup.

推荐答案

在Reddit上一些帮助后,它看起来像在我的背景,我有我需要我onModelCreating方法

After some help on reddit, it looks like in my context where I had my onModelCreating method I needed

modelBuilder.Entity<Person>();

这篇关于需要帮助迁移现有模式,包括每个类型继承表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆