Naming conventions - activa/iridium GitHub Wiki
Classes are mapped to tables using naming conventions and/or attributes. Attributes have priority over naming conventions.
The default naming convention is:
- Primary key name:
<TableName>ID
(for example:ProductID
) - Integer primary keys are auto-increment by default
- Relation column: name of the primary key of the related table
- Fields ending in "ID" are indexed.
The default naming convention will correctly map the following tables:
public class Product
{
public string ProductID; // Primary key, no autoincrement
public string Description;
public decimal Price;
public IDataSet<OrderItem> OrderItems; // related using OrderItem.ProductID
}
public class Order
{
public int OrderID; // Primary key, autoincrement
public DateTime Date;
public OrderItem[] OrderItems; // Related using OrderItem.OrderID
}
public class OrderItem
{
public int OrderItemID; // Primary key, Autoincrement
public int OrderID; // Indexed, relation key
public string ProductID; // Indexed, relation key
public int Qty;
public Order Order; // Related using "OrderID"
public Product Product; // Related using "ProductID"
}
An alternative naming convention is to use "ID" as the primary key. To use this naming convention you can redefine the naming convention as follows:
Ir.Config.NamingConvention = new NamingConvention() {
PrimaryKeyName = "ID",
OneToManyForeignKeyName = NamingConvention.CLASS_NAME + "ID",
ManyToOneLocalKeyName = NamingConvention.RELATION_CLASS_NAME + "ID"
};
The corresponding object model for this naming convention is:
public class Product
{
public string ID; // Primary key, no autoincrement
public string Description;
public decimal Price;
public IDataSet<OrderItem>; // related using OrderItem.ProductID
}
public class Order
{
public int ID; // Primary key, autoincrement
public DateTime Date;
public OrderItem[] OrderItems; // Related using OrderItem.OrderID
}
public class OrderItem
{
public int ID; // Primary key, Autoincrement
public int OrderID; // Indexed, relation key
public string ProductID; // Indexed, relation key
public int Qty;
public Order Order; // Related using "OrderID" -> "Order.ID"
public Product Product; // Related using "ProductID" -> "Product.ID"
}
To fully customize the naming convention, you can create your own naming convention class derived from NamingConvention
and tell Iridium to use it:
Ir.Config.NamingConvention = new MyNamingConvention();