I
I
ichko_vl2016-11-17 11:19:50
ASP.NET
ichko_vl, 2016-11-17 11:19:50

How to implement Entity Framework polymorphic relationships?

Hello!
Interested in the question of how to implement polymorphism, in the following configuration?
We have the following models:

public class Staff
    {
        [HiddenInput(DisplayValue = false)]             
        public int Id { get; set; }
        public string Name {get;set;}
        public virtual ICollection<StaffReports_> StaffReports { get; set; }
    }

public class StaffReports_
    {
        public int ReportId { get; set; }
        public Report Report { get; set; }
        public int? StaffId { get; set; }
        public Staff Staff { get; set; }
    }

public class Report
    {
        public int Id { get; set; }
        public DateTime DateNow { get; set; }               
        public string Autor { get; set; }                   
         public ICollection<StaffReport_> Interns { get; set; }
    }

Now there is a need to add another table for a many-to-many relationship, StaffReport1_ for example!
public class StaffReports1_
    {
        public int ReportId { get; set; }
        public Report Report { get; set; }
        public int? StaffId { get; set; }
        public Staff Staff { get; set; }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-11-18
@senal

Classes StaffReports_ and StaffReports1_ are not needed, we simply write:
in class Staff
in classReport
Next we configure (see void OnModelCreating(DbModelBuilder modelBuilder)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question