Код: Выделить всё
public interface IEntity
where TEntity: class, new()
{
// Identity column.
public long Id { get; set; }
public bool IsAuditable { get; set; }
public DateTime DateTimeCreated { get; set; }
public DateTime? DateTimeModified { get; set; }
}
public interface IEntity:
IEntity
where TEntity: class, IEntity, IEntity, new()
{ }
< /code>
Я сейчас рассматриваю использование конкретных базовых классов для всех объектов. < /p>
Рассмотрим следующую иерархию: < /p>
// Acts as a based class for all entities in the DbContext.
public class EntityBase:
IEntity
where TEntity : class, IEntity, IEntity, new()
{
// Identity column.
public long Id { get; set; }
public bool IsAuditable { get; set; }
public DateTime DateTimeCreated { get; set; }
public DateTime? DateTimeModified { get; set; }
}
public class DocumentBase : EntityBase
{
public string Name { get; set; }
}
public class ElementBase : EntityBase
{
public string Name { get; set; }
}
// Should represent a database table with all properties
// from the base class but without a discriminator column.
public class Document : DocumentBase
{
public virtual ICollection Elements { get; set; } = [];
}
// Should represent a database table with all properties
// from the base class but without a discriminator column.
public class Element : ElementBase
{
public long DocumentId { get; set; }
public virtual Document Document { get; set; }
}
public class ApplicationDbContext : DbContext
{
public DbSet Documents { get; set; }
public DbSet Elements { get; set; }
}
- Ни DocumentBase , ни elementbase не должны быть абстрактными (у нас должна быть возможность отметить их как абстрактные, если это необходимо)
- . Классы)
- Единственная общность между различными объектами будет сходиться в ConceteEntity> ConceteEntityBase> EntityBase . Никаких других путей не нужно рассматривать < /li>
< /ul>
Полученные таблицы должны иметь следующие объявления без столбца дискриминатора (без tph, tpt): < /p>
таблицы: < /p>
(ID, Isaudible, DateTimeCreated, DateTimeModified, имя, элементы)Код: Выделить всё
Document - (ID, Isauditable, DateTimeCreated, DateTimemodified, имя, документ, документ)
Код: Выделить всё
Element
Подробнее здесь: https://stackoverflow.com/questions/792 ... code-first