0

我有几个实体。每个实体都包含许多在继承的 BaseEntity 中定义的可选文档。

public class Address : BaseEntity
{

    public virtual Address Parent { get; set; }

    public string Name1 { get; set; }
    public string Name2 { get; set; }
    public string Additional { get; set; }

    public string Street { get; set; }
    public string HousNr { get; set; }
    public string ZipCode { get; set; }
    public string City { get; set; }

    public virtual Document Image { get; set; }

    public virtual ICollection<AddressContact> AddressContacts { get; set; }
    public virtual ICollection<Address> AddressPersons { get; set; }
}

public abstract class BaseEntity
{

    public Guid Id { get; set; }

    public bool IsDeleted { get; set; }
    public bool IsSystem { get; set; }
    public bool IsActive { get; set; }

    public virtual ICollection<Document> Documents { get; set; }

    public DateTime CreatedTime { get; set; }
    public string CreatedUser { get; set; }

    public DateTime? LastModifiedTime { get; set; }
    public string LastModifiedUser { get; set; }

}

和我的文档实体:

public class Document : BaseEntity
{

    public string Filename { get; set; }

    public string MIMEType { get; set; }
    public int? Length { get; set; }

    public byte[] Content { get; set; }

}

这是我的基本映射:

public abstract class  BaseEntityConfiguration<TEntity> : EntityTypeConfiguration<TEntity> where TEntity : BaseEntity
{

    public abstract string TableName { get; }
    public virtual bool HasDocument { get {return false;} }

    public BaseEntityConfiguration()
    {
        HasKey(x => x.Id);

        Property(x => x.CreatedUser).IsRequired().HasMaxLength(100);

        if (HasDocument)
        {

            //TODO: general-Mapping for Documents??

        }
        else
        {
            Ignore(x => x.Documents);
        }

        ToTable(TableName);

    }

}

我如何定义我的代码优先映射,以便最终只存在一个用于所有 comming 实体的通用文档表?

4

0 回答 0