Entity Framework - Data Model


The Entity Data Model (EDM) is an extended version of the Entity-Relationship model which specifies the conceptual model of the data using various modelling technique. It also refers to a set of concepts that describe data structure, regardless of its stored form.

EDM supports a set of primitive data types that define properties in a conceptual model. We need to consider 3 core parts which form the basis for Entity Framework and collectively it is known as Entity Data Model. Following are the three core parts of EDM.

  • The Storage Schema Model
  • The Conceptual Model
  • The Mapping Model

The Storage Schema Model

The Storage Model also called as Storage Schema Definition Layer (SSDL) represents the schematic representation of the backend data store.

EDM

The Conceptual Model

The Conceptual Model also called as Conceptual Schema Definition Layer (CSDL) is the real entity model, against which we write our queries.

The Mapping Model

Mapping Layer is just a mapping between the Conceptual model and the Storage model.

The logical schema and its mapping with the physical schema is represented as an EDM.

  • Visual Studio also provides Entity Designer, for visual creation of the EDM and the mapping specification.

  • The output of the tool is the XML file (*.edmx) specifying the schema and the mapping.

  • Edmx file contains Entity Framework metadata artifacts.

Schema Definition Language

ADO.NET Entity Framework uses an XML based Data Definition Language called Schema Definition Language (SDL) to define the EDM Schema.

  • The SDL defines the Simple Types similar to other primitive types, including String, Int32, Double, Decimal, and DateTime, among others.

  • An Enumeration, which defines a map of primitive values and names, is also considered a simple type.

  • Enumerations are supported from framework version 5.0 onwards only.

  • Complex Types are created from an aggregation of other types. A collection of properties of these types define an Entity Type.

The data model primarily has three key concepts to describe data structure −

  • Entity type
  • Association type
  • Property

Entity Type

The entity type is the fundamental building block for describing the structure of data in EDM.

  • In a conceptual model, entity types are constructed from properties and describe the structure of top-level concepts, such as a Students and Enrollments in a business application.

  • An entity represents a specific object such as a specific Student or Enrollment.

  • Each entity must have a unique entity key within an entity set. An entity set is a collection of instances of a specific entity type. Entity sets (and association sets) are logically grouped in an entity container.

  • Inheritance is supported with entity types, that is, one entity type can be derived from another.

Entity Type

Association Type

It is another fundamental building block for describing relationships in EDM. In a conceptual model, an association represents a relationship between two entity types such as Student and Enrollment.

  • Every association has two association ends that specify the entity types involved in the association.

  • Each association end also specifies an association end multiplicity that indicates the number of entities that can be at that end of the association.

  • An association end multiplicity can have a value of one (1), zero or one (0..1), or many (*).

  • Entities at one end of an association can be accessed through navigation properties, or through foreign keys if they are exposed on an entity type.

Property

Entity types contain properties that define their structure and characteristics. For example, a Student entity type may have properties such as Student Id, Name etc.

A property can contain primitive data (such as a string, an integer, or a Boolean value), or structured data (such as a complex type).

Advertisements