The Domain Model

Entity Context

The EntityContext class is used for interacting with Entity Objects. An Instance of the EntityContext class encapsulates - a connection to the database, metadata that describes the model, and an object state manager that tracks objects during create, update and delete operations.

AgileFx framework generates an Object layer based on the defined data model, which includes the entity context definitions and Entity Types. The entity context definition contains an EntityContext derived class that typically has a set of properties that returns a collection of entities of the specified type. The default name for the derived class is Entities. The context name can be changed by modifying the property - "Data Context Name" on the domain model properties.

agilefx modeler

Entities

A base class or an interface can be set on the entities in the domain model by using the designer context menu (right click on the designer) option - "Advanced -> Set Base Class and Interface".

agilefx modeler

Relationships

The types of relationships that can be represented using the AgileFx modeler are

Inheritance

The base class property on an entity can be set to another entity defined in the domain model. Multi level inheritance is also supported. So an already derived Entity can be the base class for another Entity.

agilefx modeler

To implement this type of relationship when starting with the database first approach, the base entity table Identifier column would be set as the primary key and also an Identity column, the derived entity table Identifier column would be a primary key and have a foreign key relationship to the Identifier column of the base entity table.

One to One

The multiplicity of both entities in an association can be set to "One" or "Zero One" to create a "One to One" relationship. This is set on the multiplicity property of the concerned navigational property on the two entities.

agilefx modeler

To implement this with the "database first approach", the foreign key name will have to be named in either of the formats given below


"Zero or One to One"
FK_<FK_ENTITY_NAME>_<FK_ENTITY_NAVIGATIONAL_PROPERTY>_<PK_ENTITY_NAME>_<PK_ENTITY_NAVIGATIONAL_PROPERTY>
_ZeroOneToOne

"One to One"
FK_<FK_ENTITY_NAME>_<FK_ENTITY_NAVIGATIONAL_PROPERTY>_<PK_ENTITY_NAME>_<PK_ENTITY_NAVIGATIONAL_PROPERTY>
_OneToOne

agilefx modeler

One to Many

The multiplicity of one entity in an association can be set to "One" or "Zero One" and the other to "Zero Many" to create a "One to Many" relationship.

In the database one entity table would have a foreign key column set to the primary key column of the other entity table.

Many to Many

The multiplicity of both entities in an association can be set to "Zero Many" to set this kind of relationship.

In the database there would be a map table that would have only two columns, each having a foreign key to primary key columns of the related two entity tables.