【发布时间】:2018-02-04 12:48:35
【问题描述】:
如果我在 TPH 配置中有一个基类和两个派生类,如何在 fluent API 中配置派生类的标量属性(例如字符串的长度)?
示例: 公共枚举 PersonType { Employee, Manager }
public abstract class Person
{
public string FirstName {get; set;}
public string LastName {get; set;}
}
public class Employee : Person
{
public string Designation {get; set;}
}
public class Manager : Person
{
public string Division {get; set;}
}
//fluent api config
internal class PersonConfig : EntityTypeConfiguration<Person>
{
public PersonConfig()
{
Property(p => p.FirstName) .HasMaxLength(250);
Property(p => p.LastName) .HasMaxLength(250);
Map<Employee>(e => e.Requires(x => x.PersonType).HasValue());
**//how to configure Designation ?**
Map<Manager>(m => m.Requires(y => y.PersonType).HasValue());
**//how to configure Division ?**
}
}
【问题讨论】:
标签: entity-framework