Entities

Entity definitions need to follow certain rules in order to work with Xams.

Entity Rules

  1. The Table name (specified with the Table attribute) and must match the name of the class.
  2. The Primary Key must be a Guid and take the shape of TableName + Id ie: WidgetId.
  3. Every entity must have either a string Name field or a string field with the attribute UIName.
  4. Composite Primary Keys are not allowed.
  5. See React Data Types for fields types that are compaitabile with the React components.

Project.Common / Entities / Widget.cs

// Table attribute is required
[Table("Widget")] // Table attribute matches class name
public class Widget
{
// Primary key is table name + Id and of type Guid
public Guid WidgetId { get; set; }
public string? Name { get; set; } // Name field or string field with UILookupName is required
}

Cascade Delete

If a relationship is defined as non-nullable, it becomes required and will be deleted if the related record is removed. To prevent cascade deletion, the relationship can be made nullable.

You can still make the field required by using the UIRequired attribute.

Project.Common / Entities / Widget.cs

[Table("Widget")]
public class Widget : BaseRecord
{
public Guid WidgetId { get; set; }
// Name is required
public string Name { get; set; }
// Company is required, cascade delete will delete this record
public Guid CompanyId { get; set; }
public Department Company { get; set; }
// Manufacturer is nullable, cascade delete will set this to null
public Guid? ManufacturerId { get; set; }
public Manufacturer? Manufacturer { get; set; }
// Contact is nullable, cascade delete will set this to null
// but upon create & update it's always required
[UIRequired]
public Guid? ContactId { get; set; }
public Contact Contact { get; set; }
}

Was this page helpful?