Я хочу получить доступ к свойствам из производного класса в TPH.
Базовый класс
public abstract class Author
{
public int AuthorId { get; set; }
public AuthorType AuthorType { get; set; }
public ICollection<Post> Posts { get; set; }
}
Производный класс
public class Organization : Author
{
public string Name { get; set; }
}
Конфигурации
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Author>()
.HasDiscriminator(a => a.AuthorType)
.HasValue<Person>(AuthorType.Person)
.HasValue<Organization>(AuthorType.Organization);
modelBuilder.Entity<Author>()
.HasMany(p => p.Posts);
modelBuilder.Entity<Post>()
.HasOne(a => a.Author)
.WithMany(p => p.Posts);
}
Я хочу получить доступ к свойству Имя в сообщениях организации:
Author author = new Organization { Name = "CA", OrganizationType = OrganizationType.NonProfit};
Post post = new Post { Subject = "News", Author = author, Tag = PostTag.SualatUpdate};
context.Add(author);
context.Add(post);