Creating classes - activa/iridium GitHub Wiki

Classes for storing data can be defined as simple POCO classes, without any attributes or base classes.

For example:

public class Product
{
   public int ProductID;
   public string ProductName;
   public decimal Price;
}

The default naming convention will map this class to a table "Product" with a primary key "ProductID". The default naming convention is to use <Table>ID as primary key and the name of the primary key of the related table for relations. The naming convention is fully configurable though. See Naming conventions for more information.

You can use the following attributes to customize the mapping of a class to a record:

Attribute On Description
[Table.Name] Class Specifies the name of the table for a class
[Column.PrimaryKey(...)] Field Defines a primary key field, optionally autoincremented
[Column.Name(...)] Field Specifies the name of the column a field should be mapped to
[Column.Size(...)] Field The size (width) of a field in the database. Mostly used with string and decimal data types. The scale parameter is optional
[Column.LargeText] Field Marks the field as a large text field (blob text)
[Column.Indexed(...)] Field Creates an index for this field, optionally specifying the name of the index and the position of the field within that index
[Column.Null] Field Specifies that a field should be nullable in the database
[Column.NotNull] Field Specifies that a field should not be nullable in the database
[Column.Ignore] Field Does not map the field to a database field

For example:

[Table.Name("Products")]
public class Product
{
    [Column.PrimaryKey(AutoIncrement=true)]
    public int ProductID;

    [Column.Size(100) , Column.NotNull]
    public string ProductName;

    [Column.LargeText]
    public string ExtendedDescription;

    public decimal Price;    
}

Defining relations

See Relations

⚠️ **GitHub.com Fallback** ⚠️