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
c # entity-framework ef-code-first


source to share


No one has answered this question yet

See similar questions:

48
What is the best way to implement Polymorphic Association in SQL Server?
13
How to implement polymorphic associations in an existing database
3
one to one or zero relationship with OneWay CascadeOnDelete

or similar:

1252
Try to speed up my code?
595
First Code - Model / Database First
490
There is already an open DataReader associated with this Command, which must be closed first
268
Create code first, many to many, with additional fields in the join table
259
Ignoring Class Property in Entity Framework 4.1 Code First
3
Loading a property after attaching an object
1
Many of the many are related to WPF Datagrid
0
Cannot inherit properties of custom types in Code-First
0
Failed to register Autofac for project structure
0
Zero foreign key code in Entity Framework first



All Articles
Loading...
X
Show
Funny
Dev
Pics