EntityTypeConfiguration中的Discriminator列 [英] Discriminator column in EntityTypeConfiguration

查看:48
本文介绍了EntityTypeConfiguration中的Discriminator列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在EntityTypeConfiguration中为TPH结构指定鉴别器列/值,而不是DbContext的OnModelCreating方法。

Is it possible to specify the discriminator column/value for a TPH structure in the EntityTypeConfiguration rather than the OnModelCreating method of the DbContext.

基本原理是我喜欢的所有关于类的持久性模型的信息都在一个地方而不是在多个位之间分开。

Rationale is that I like to have all info about a class's persistence model in one place rather than split between multiple bits.

推荐答案

嗨Paul,

是的,当您在OnModelCreating中调用modelBuilder.Entity< MyClass>()时,它只会返回一个EntityTypeConfiguration,因此它与API表面完全相同。

Yes, when you call modelBuilder.Entity<MyClass>() in OnModelCreating it just gives you back an EntityTypeConfiguration, so it's exactly the same API surface.

public class ProductConfig : EntityTypeConfiguration<Product>
{
  public ProductConfig()
  { 
    Map<Product>(m => m.Requires("Type").HasValue("Current"))
      .Map<DiscontinuedProduct>(m => m.Requires("Type").HasValue("Old")); 
  }
}

 

~Rowan


这篇关于EntityTypeConfiguration中的Discriminator列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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