0

What is a good way to represent reference data in Entity framework?

For example: I normally create two tables in the database

valid_type
    valid_type_id int not null,
    name varchar(80),
    description varchar(255)

valid_value (Note: PK is valid_type_id, valid_value_id)
    valid_value_id int not null
    valid_type_id int not null,
    name varchar(80),
    description varchar(255)

These two tables hold all of my reference data.

I then create a table that uses it as

Rule
  rule_id int not null,
  rule_type_id int not null,
  rule_system_id int not null,
  value1 varchar(80),
  etc

I can then have enums that can be used by EF

public enum ValidTypes
    RuleTypes= 0,
    SomethingElse = 1,

public enum RuleTypes
    QualityControl = 0,
    PostProcessing = 1,
    etc

So, now what is a good way to represent this in EF code first? would a Table-Per-Hierarchy be a good approach? How would that be represented in the EF classes? as the "base" type"? or the "derived type"?

This has to be a fairly common scenario, but I have not found much on it with my google-fu.

Keith
  • 1,119
  • 2
  • 12
  • 23
  • Typically, I put a surrogate-key in the "valid_value) table...and have only one FK column in my "Rule" table. (Rule.ValidValueSurrogateKey=> references => valid_value.ValidValueSurrogateKey) See this post for some potential help. http://stackoverflow.com/questions/31372549/code-first-enumerations-put-into-lookup-tables – granadaCoder Jun 07 '16 at 16:27
  • In TPH code first approach the idea is to break the representation of a single table into multiple entities in the conceptual model. The conceptual model would involve creation of a base abstract class. You have mentioned three tables on your database side namely valid_type, valid_value and Rule. For which table you are looking for TPH approach out of these three. Are these three tables in any way related to each other? – RBT Jun 07 '16 at 22:42

0 Answers0