0

I am working on an .NET web app that handles user profiles. We use SQL Server and EF.

Here is my view (I only show some columns for brevity):

Profile
---------------
EmployeeNumber (not null)
Name (null)
HireDate (null)
POST_ID (null)
Station (null)

The thing is, Department A uses POST_ID and not Station while Department B uses Station but not POST_ID. So for my models, I thought I would create a base class with the common fields and then inherit department specific classes from it and include the department specific fields.

Here are my classes:

public class Profile
{
    [Key]
    public int EmployeeNumber {get;set;}
    public string Name {get;set;}
    public DateTime HireDate {get;set;}
}

[Table("Profile")]
public class DeptA_Profile : Profile
{
    public int POST_ID {get;set;}
}

[Table("Profile")]
public class DeptB_Profile : Profile
{
    public string Station {get;set;}
}

However, when I run my code I get the following error:

The entity types 'DeptA_Profile' and 'DeptB_Profile' cannot share table 'Profile'
because they are not in the same type hierarchy or do not have a valid one to one
foreign key relationship with matching primary keys between them.

So I am obviously not doing what I am trying to do in the correct manner. Can I get some help with this? I am open to changing my models if there is a better way.

Mr. Spock
  • 315
  • 1
  • 9

0 Answers0