I have two "entities", Job Code and Job Family:
public class JobCode{
public int Code {get;set;}
public string Name {get;set;}
}
public class JobFamily{
public int Code {get;set;}
public string Name {get;set;}
}
JobCode.Code
is a 5-digit code, and JobFamily.Code
is 2 digits, which correspond with the first 2 digits of a Job Code, so there is an intrinsic relationship that I would like to capture in either the code or the database.
If I use code-first Entity Framework (or if I use database-first), is there a way to get something like:
CREATE TABLE JobFamily
(
Code int PRIMARY KEY,
Name varchar(255)
);
CREATE TABLE JobCode
(
Code int PRIMARY KEY,
Name varchar(255),
JobFamily AS (Code / 1000) FOREIGN KEY REFERENCES JobFamily(Code)
);
Is this even possible in SQL Server? I can't find anything saying it's not, but I can't find anyone trying to do it either...