EF: one-to-many mapping code
I have multiple entities. Each object includes many optional documents, defined in the inherited 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; }
}
and my Document-Entity:
public class Document : BaseEntity
{
public string Filename { get; set; }
public string MIMEType { get; set; }
public int? Length { get; set; }
public byte[] Content { get; set; }
}
and here's my basic display:
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);
}
}
how can I figure out my first code mapping so that in the end there is only one common document table for all incoming objects?
0
source to share
No one has answered this question yet
See similar questions:
or similar: