Hi All,
I can't remember if this is possible, but I'm sure it should be.
I have a table in my database which looks as follows:
Id [bigint] [primary key + auto incremented]
Name [nvarchar(50)]
UserType [tinyint]
LineManagerId [bigint] [nullable]
DivisionHeadId [bigint] [nullable]
There is a relationship limiting LineManagerId and DivisionHeadId to be valid ID's from the same table.
I'm sure you can from that picture the structure? If not ask :-)
I'm using Entity Framework to create my objects and it brings in the User table with no problem.
What I want to do is have the following objects:
public class User
public class LineManager : User
public class DivisionHead : User
These should all map to the same table using the UserType field as the differentiating factor.
Users should have 0..1 Line Manager's and 0..1 DivisionHead's
LineManagers can have many users and 0..1 DivisionHead's, and the class should have a "users" navigation property.
DivisionHeads can have many users and the class should have a "users" navigation property.
I've been able to make a derived class from my Users entity, however when I try to build it I get the error
UserType has no default value and is not nullable
yet, I've set the default value of UserType to be 1.
(I tried to convert this value to an enum but that results in the following error:
default values are allowed only for non-spatial primitive types
)
So my question is, how can I achieve this? Or more accurately what am I missing as I have the classes I just can't make them work?
I would have thought it would be straightforward and I feel I'm close but my research so far isn't shedding any light on the issue. I'm hoping you you guys can?
Thanks,