DatabaseAttributeattribute. We call these types database classes. The names and namespaces we give to these C# classes will be the names and namespaces of the corresponding database tables.
IDatabaseContext.Insert<T>()method are stored in the Starcounter database persistently.
Personclass with a custom default constructor:
setaccessors and with one of the supported data types. The
Persondatabase class below defines two such columns,
Namestring of a
Person. We could do this by introducing a calculated property. These computed properties do not have the same restrictions as column properties, since they are transient and not bound to the corresponding database table.
getaccessors of computed properties of database classes. This way we can extend object-oriented principles like encapsulation onto the persistent nature of database objects. Let's expand our
Personclass with a
Motherone-to-many relational property:
Childrenwith the purpose of listing, for each Person
pin the database where
mis the value of the
Personinstance lives in. We can achieve this by calling the static method
CREATE INDEXSQL queries. Both unique and not unique indexes are supported. Since
CREATE INDEXis a DDL statement, we use the
IDdlExecutorto perform it, outside an active transaction. We can obtain the
IDdlExecutorfrom the service provider.
Companyentities such that a single person can hold multiple shares in multiple companies, and a single company can have multiple shareholders. For this, let's use the association class
ShareOwnership. We can then make queries to this database class to calculate useful information in
Companythat is exposed using computed properties. Lastly, we make sure that indexes are registered for the
ShareOwnershipsince we will be quering them a lot.
DatabaseAttributeattribute decoration is inherited from any base class to its subclasses, meaning that any class that directly or indirectly inherits a class that is decorated with the
DatabaseAttributeattribute becomes a database class. In the example above, both
CorporateCustomerbecome database classes due to them inheriting
CorporateCustomertable also are contained in the
Customertable. The result of the
SELECT C FROM Customer cSQL query will contain all rows from
Customeras well as all rows from subclasses of
Oidto each database object. The key is unique across all table rows in the entire database. Any id value is used only once, and not reused in the future, even if the original object was deleted. We can configure the range to use for oid's using the
LastObjectIdoptions in the database creation options.
IDatabaseContexttype defines methods for working with object
Oid's. For the examples above, let's assume that
dbholds a reference to an instance of
IDatabaseContext, recieved from an
ITransactorwhen starting a new database transaction.
Oidfrom a database object
0) is not a valid
object.Equalsmethod or the
Equalsinstance method for each database class instance. Comparing database objects with
==operator always returns
falseif any of the objects are retrieved from the database.