ERD family: entities, attributes and relationships

Overview

Base Control: ERDControl : MaterialControl
Namespace: Beep.Skia.ERD

The ERDControl is the root control for this diagram family. It inherits MaterialControl and provides shared port management, styling, and template methods for all nodes in the family.

This family contains 4 node types.

Node Types

Node ClassShapeDescription
ERDEntityTable rectangleDatabase table with columns, primary keys, foreign keys, and row-level connection points for per-column relationships.
ERDAttributeOvalEntity attribute with name, data type, and nullable flag.
ERDRelationshipDiamondRelationship between entities with cardinality (1:1, 1:N, M:N) and Crow's Foot notation.
DDLExporterN/A (utility)Generates CREATE TABLE SQL from ERDEntity definitions including PKs, FKs, indexes, and constraints.

ERDEntity

Database table with columns, primary keys, foreign keys, and row-level connection points for per-column relationships.

ShapeTable rectangle
Input Ports2+ (left)
Output Ports2+ (right)

ERDAttribute

Entity attribute with name, data type, and nullable flag.

ShapeOval
Input Ports1
Output Ports1

ERDRelationship

Relationship between entities with cardinality (1:1, 1:N, M:N) and Crow's Foot notation.

ShapeDiamond
Input Ports2+ (left/top)
Output Ports2+ (right/bottom)

DDLExporter

Generates CREATE TABLE SQL from ERDEntity definitions including PKs, FKs, indexes, and constraints.

ShapeN/A (utility)
Input Ports—
Output Ports—

Connection Points

Every node in this family exposes connection points (ports) for linking to other nodes. Port positions are computed lazily by LayoutPorts(), which runs when MarkPortsDirty() flags the layout as stale after a move or resize.

Node ClassInput PortsOutput PortsExtra
ERDEntity2+ (left)2+ (right)1 per field (left/right)
ERDAttribute11—
ERDRelationship2+ (left/top)2+ (right/bottom)—
DDLExporter———

Connection Conventions

When building diagrams with this family, follow these conventions:

  • ERDEntity uses row-level connection points for per-column relationships
  • Multiplicity markers displayed on line endpoints (1, N, M)
  • DDLExporter generates SQL from entity metadata
  • ConnectionPoint.DataType and RowId enable schema validation

Usage Example

Complete example showing creation, node placement, and connection:

C# Example

var erd = new ERDControl
{
    X = 100, Y = 50,
    Width = 700, Height = 500
};
drawingManager.AddComponent(erd);

var entity = new ERDEntity
{
    X = 200, Y = 100,
    TableName = "Customers",
    Width = 200, Height = 150
};
entity.AddField("Id", "int", isPrimaryKey: true);
entity.AddField("Name", "varchar(100)");
entity.AddField("Email", "varchar(255)");
drawingManager.AddComponent(entity);

var attr = new ERDAttribute
{
    X = 450, Y = 100,
    AttributeName = "Email",
    DataType = "varchar(255)"
};
drawingManager.AddComponent(attr);

var rel = new ERDRelationship
{
    X = 200, Y = 300,
    RelationshipType = RelationshipType.OneToMany,
    Text = "places"
};
drawingManager.AddComponent(rel);

// Row-level connections with multiplicity
drawingManager.ConnectComponents(entity.GetFieldPoint("Id"), rel.InPoints[0]);
drawingManager.ConnectComponents(rel.OutPoints[0], attr.InPoints[0]);

// Export DDL
var exporter = new DDLExporter();
string sql = exporter.Export(entity);