3. HasMany

Defines a 1-n relationship for a child object.

Example:

[ElementaryClass]
public class Customer
{
  [Persist]
  public string FirstName;

  [Persist]
  public string LastName;

  [HasMany(typeof(Order))]
  public List<Order> Orders;
}

Remarks

Elementary will automatically infer the parent and child columns to use. Let's assume that this is our table structure:

Customer
--------------------
- CustomerId
- FirstName
- LastName

Order
--------------------
- OrderId
- CustomerId

If the columns aren't explicitly defined, Elementary will look for the following matches:

Options

ChildColumnDefines the column to use in the child table
[ElementaryClass]
public class Customer
{
  [Persist]
  public string FirstName;

  [Persist]
  public string LastName;

  [HasMany(typeof(Order), ParentColumn="customerid", ChildColumn="customerid")]
  public List<Order> Orders;
}
ParentColumnDefines the column to use in the parent table
[ElementaryClass]
public class Customer
{
  [Persist]
  public string FirstName;

  [Persist]
  public string LastName;

  [HasMany(typeof(Order), ParentColumn="customerid", ChildColumn="customerid")]
  public List<Order> Orders;
}
ChildPropertyDefines the property to use in the child table. This is translated behind the scenes into the corresponding column
[ElementaryClass]
public class Customer
{
  [Persist]
  public string FirstName;

  [Persist]
  public string LastName;

  [HasMany(typeof(Order), ParentProperty="Id", ChildProperty="CustomerId")]
  public List<Order> Orders;
}
ParentPropertyDefines the property to use in the parent table. This is translated behind the scenes into the corresponding column
[ElementaryClass]
public class Customer
{
  [Persist]
  public string FirstName;

  [Persist]
  public string LastName;

  [HasMany(typeof(Order), ParentProperty="Id", ChildProperty="CustomerId")]
  public List<Order> Orders;
}