C#C
C#3y ago
2 replies
morry329#

✅ '' does not contain a definition for '' and no accessible extension method '' can be found

I have this data model
 public class Employee : Pilot
    {
        public Employee()
        {
            
        }
        public int PersonId { get; set; }
        public DateTime StartDate { get; set; }
        public int BossId { get; set; }

        public string Person { get; set; }
        
        
     }


And the error pops out in the OnModelCreating method:
`
modelBuilder.Entity<Employee>(entity =>
            {
         
                entity.HasOne(d => d.Person)
                .WithOne(p => p.Employee) /*ERROR, 'string' does not contain a definition for 'Employee' and no accessible extension method 'Employee' accepting a first argument of type 'string' could be found*/
                .HasForeignKey<Employee>(d => d.PersonId) 
                .OnDelete(DeleteBehavior.Restrict)
                .HasConstraintName("FK_MI_Employee_PE_Person");
            });
`

I have tried to inject the Employee keys into the neighbouring data model like this, but to no avail
`
public class Person
    {
        public Person()
        {
            //Employee = new HashSet<Employee>();
        }
        public Pilot Pilot { get; set; }
        public string Employee { get; set; }
    }

Could anyone point me in the right direction?
Was this page helpful?