У меня есть следующие два класс:Entity Framework
public class Department
{
public int DepartmentID { get; set; }
public string Name { get; set; }
public int EmployeeCount { get; set; }
public int MinimumCoverage { get; set; }
public virtual List<Approver> Approvers { get; set; }
public virtual List<Employee> Employees { get; set; }
}
public class Employee
{
public int EmployeeID { get; set; }
public string Username { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int DepartmentID { get; set; }
public virtual Department Department { get; set; }
public DateTime StartDate { get; set; }
public decimal DaysAccrued { get; set; }
public decimal DaysUsed { get; set; }
public decimal DaysRemaining { get; set; }
public bool IsManager { get; set; }
public bool IsApprover { get; set; }
}
Я хочу, чтобы работник принадлежит отделу, используя DepartmentID и в классе Департамента иметь средства со списком всех сотрудников в отделе, но Я получаю следующую ошибку в настройке EF:
Дополнительная информация: Сущности в 'HolidayManagerContext.Employees' участвуют в отношении 'Employee_Department'. 0 связанных «Employee_Department_Target». 1 'Employee_Department_Target'
Мой контекст выглядит следующим образом:
public partial class HolidayManagerContext : DbContext
{
public HolidayManagerContext()
: base("name=HolidayManagerContext")
{
}
public virtual DbSet<Employee> Employees { get; set; }
public virtual DbSet<Approver> Approvers { get; set; }
public virtual DbSet<Request> Requests { get; set; }
public virtual DbSet<Decision> Decisions { get; set; }
public virtual DbSet<Department> Departments { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Employee>()
.Property(e => e.DaysAccrued)
.HasPrecision(18, 1);
modelBuilder.Entity<Employee>()
.Property(e => e.DaysUsed)
.HasPrecision(18, 1);
modelBuilder.Entity<Employee>()
.Property(e => e.DaysRemaining)
.HasPrecision(18, 1);
modelBuilder.Entity<Employee>()
.HasRequired(e => e.Department)
.WithMany()
.WillCascadeOnDelete(false);
}
}
Код Первый? Любая свободная конфигурация? –
Добавить Контекст также –
@IvanStoev задал вопрос обновлен – Jay