Finding and Reading Objects
Except for a few calls to Factory (to make a database or initialize the environment for reading) or Repostory (to Initialize the Repository with a database file or perform a unit of work), your code should only ever interact with the generated Domain objects. If you have specialty code in your tables, you should wrap that behaviour with code in your Domain Objects. See the section "Custom Searches" for additional information.
To read, you must initialize the environment with "Factory.Initialize();". This method is generated and represents the all the code needed to read from all of the tables/classes into your code. It contains calls these two calls, one of for each table the system generates:
Repository.AddGetOIDMethod<PlanetTable>( PlanetTable.GetByOID );
Repository.AddReadFactory<PlanetTable>( PlanetReadFactory );
"AddGetOIDMethod" tells the repository which method it can call to get an instance from the database when it needs a specific table instance and has an OID for that table. It's used by the LazyMaster<> generic class to find the master instance in an association.
"AddReadFactory" tells the repository which method it can call to construct domain instances from table instances. You can find the method it uses in the Factory class. All it does is have a switch statement on the SubType with each constructor loading from the table instance the columns that make up it's class. In single table inheritance, there may be some columns in some domain objects unused in others.
Find Methods
In the domain and table, by default, you can read individual rows by OID or all the rows out of a table. In the model, you can mark any attribute with a stereotype called "find". This will generate a method to search for instances based on a single attribute value being specified. For example, in the how to model video, it created this method in the Settlement class.
/// <summary>
/// Use to find Settlement instances that match a provided "Name".
/// </summary>
public static IEnumerable<Settlement> FindByName(string aName) {
return Repository.Factory<SettlementTable,Settlement>( SettlementTable.FindByName( aName ) );
}
In situations where you need a more complicated search, please review the section on custom searches.
To read, you must initialize the environment with "Factory.Initialize();". This method is generated and represents the all the code needed to read from all of the tables/classes into your code. It contains calls these two calls, one of for each table the system generates:
Repository.AddGetOIDMethod<PlanetTable>( PlanetTable.GetByOID );
Repository.AddReadFactory<PlanetTable>( PlanetReadFactory );
"AddGetOIDMethod" tells the repository which method it can call to get an instance from the database when it needs a specific table instance and has an OID for that table. It's used by the LazyMaster<> generic class to find the master instance in an association.
"AddReadFactory" tells the repository which method it can call to construct domain instances from table instances. You can find the method it uses in the Factory class. All it does is have a switch statement on the SubType with each constructor loading from the table instance the columns that make up it's class. In single table inheritance, there may be some columns in some domain objects unused in others.
Find Methods
In the domain and table, by default, you can read individual rows by OID or all the rows out of a table. In the model, you can mark any attribute with a stereotype called "find". This will generate a method to search for instances based on a single attribute value being specified. For example, in the how to model video, it created this method in the Settlement class.
/// <summary>
/// Use to find Settlement instances that match a provided "Name".
/// </summary>
public static IEnumerable<Settlement> FindByName(string aName) {
return Repository.Factory<SettlementTable,Settlement>( SettlementTable.FindByName( aName ) );
}
In situations where you need a more complicated search, please review the section on custom searches.