The EAV/CR Model of Data Representation
I should warn you that the name "EAV/CR", on occasion, can be somewhat of a misnomer. EAV/CR originally stood for "entity-attribute-value with classes and relationships" and in some of the databases that we have implemented, this definition still holds. However, depending on the database that you are building, some, or even most, of the classes of data are best represented as old-fashioned relational tables. EAV/CR is really defined by its metadata infrastructure, rather than the fact that the representation of data may or may not be in EAV form.
In production systems, using EAV/CR is something like driving a car using the stick shift. It gives you more control than using automatic transmission, but is also somewhat trickier than using old-fashioned design approaches. Therefore, you use it only when you absolutely need to.
In the account below, we use the word "class" as the equivalent of "database table" and "attribute" as the equivalent of "database column". While this usage is somewhat lax, this is what you end up doing in the vast majority of cases when you are using a relational database to store object-modeled data.
EAV/CR is an approach that seeks to facilitate the rapid development of interfaces to data (and/or their dynamic creation) through the recording of "rich" metadata that not only describes every element in the database from a "database" perspective, but also from a "presentation" and "user interaction" perspective.
The word "rapid" comes with a caveat- in earlier editions of their classic "Camel" book on Perl, Larry Wall and Randall Schwartz describe laziness as an attribute of truly great programmers - they first build a framework (the hard part, which is slow going), and then use the framework to automate chores (the easy/rapid part, which allows laziness). EAV/CR is the basis for such a framework.
By "database" perspective, we include info such as data type, constraints, relationships between classes, and so forth
Presentation/user interaction metadata encompasses details such as:
How a conceptual column in the database is to be displayed: e.g., as a text box, a scrollable text area, listbox, combo.
If the column represents a foreign key, how the values are to be searched. A combo/list box is an appropriate visual metaphor when the list of possible values does not exceed, say, 30. It is inappropriate for searching through 3000 values, and here, you want the system to place a "search" button that lets you search the "primary key" table equivalent either by bringing up a "search" form (where you query this table based on particular fields of interest", or in Google fashion, where you type in one or more keyphrases, and the system searches all the fields that have been designated as "Help" fields.
When you present a single record from a particular class in a "form view", you typically also want to present related (many-to-one) records from other classes, using a "sub-form" visual metaphor. You may wish to drill down into the details of an individual related record (by opening up a new form for that class).
It would be convenient if you could build such interfaces automatically, by specifying presentation metadata in great detail and then letting the system generate an interface for you. This is what EAV/CR is about: in addition, the metadata serves as detailed and rigorous documentation for the system and its semantics. It also makes data interchange possible with programs that expect conventional (one-attribute-per-column) table structure.
The interface that is generated may be completely dynamic, or may have some static elements - the former is usually OK for browsing: the SenseLab Web site is mostly dynamic. The latter is usually required when you are doing data entry with some elaborate data validation - generating all the validation code every time the class is accessed may be too much of an overhead, and a Web page with static elements improves response. The TrialDB Web site mostly uses pages with static elements.
EAV = Entity-Attribute-Value. EAV/CR = EAV with Classes and Relationships
Conceptually, a table with three columns:
The table has one row for each Attribute-Value pair.
In reality, we prefer to segregate values based on data type, so as to support indexing and let the database perform type validation checks where possible. So there are separate EAV tables for strings, real and integer numbers, dates, long text and Binary large objects (BLOBS).
EAV/CR overlays an object-oriented framework on top of an EAV physical structure.
The EAV/CR Schema: Data Tables

The EAV/CR Schema: Metadata Tables

Example: Data on Nigrostriate Neurons
Neurons:
Nigrostriatal
Anatomical Origin: Pars Compacta of Substantia Nigra.
Projecting To: Corpus Striatum
Neurochemical/s Released: Dopamine
Receptor/s involved: D2
Electro-physiological Function: Inhibitory
Neurons Projected To (Efferents): Striato-Pallidal neurons,
Striato-Striatal neurons
Neurons Providing Input (Afferents): Pars Reticulata of Substantia
Nigra, Striato-Nigral fibers.
Representing the Nigrostriate Example in EAV/CR
A. Metadata for the Neuronal_Info Association Class
Attributes:
|
Attribute Name |
Datatype |
| Primary_Neuron | Class, Neuron |
| Soma_location | Class, Anatomical_Location |
| Axon_Terminus_Location | Class, Anatomical_Location |
| Neurotransmitter_released | Class, Neurotransmitter, multi-instance |
| Receptor_Type | Class, Receptor, multi-instance |
| Electrophysiological_Effect | Integer (member of a Choice Set) |
| Receptor_Type | Class, Anatomical_Location |
| Efferent_Neuron | Class, Neuron, multi-instance |
| Afferent_Neuron | Class, Neuron, multi-instance |
B. EAV Data for the Nigrostriate Neuron
| Entity ID | Attribute | Value |
| 100 | <Primary_Neuron> | <Nigrostriate cell> |
| 100 | <Soma_location> | <ParsCompacta, S.Nigra> |
| 100 | <Axon_Terminus_Location> | <Corpus Striatum> |
| 100 | <Neurotransmitter_released> | <Dopamine> |
| 100 | <Receptor_Type> | <D2> |
| 100 | <Efferent_Neuron> | <Striato-pallidal> |
| 100 | <Efferent_Neuron> | <Striato-striatal> |
| 100 | <Afferent_Neuron> | <Striato-nigral> |
| 100 | <Afferent_Neuron> | <Pars Reticulata, S.Nigra> |
| ... | ... | ... |
| 100 | <Electrophys_effect> | <2 = Inhibition> |
Relationship Details as Inverted-File Indexes