Advanced usage
HasAndBelongsToMany with intermediate type
TODO
Accessing more than one database
TODO: Describe how it works
Connection information is associated with a Type. Subclasses of the configured type inherit the active record configuration.
For Example:
<activerecord> <config> <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" /> <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" /> <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" /> <add key="hibernate.connection.connection_string" value="Data Source=.;Initial Catalog=test;Integrated Security=SSPI" /> </config> <config type="Castle.ActiveRecord.Tests.Model.Test2ARBase, Castle.ActiveRecord.Tests"> <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" /> <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" /> <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" /> <add key="hibernate.connection.connection_string" value="Data Source=.;Initial Catalog=test2;Integrated Security=SSPI" /> </config> </activerecord>
Here are a few caveats that you might encounter when trying to get multiple databases working properly.
Your Test2ARBase class must be abstract:
[ActiveRecord]
public abstract class Test2ARBase<T> : ActiveRecordBase<T>
If your are using ActiveRecordValidationBase<T>:
[ActiveRecord]
public abstract class Test2ARValidationBase<T> : ActiveRecordValidationBase<T> where T : class
You must include the base class in the list of models in the call to ActiveRecordStarter.Initialize():
ActiveRecordStarter.Initialize(config, typeof(Test2ARBase<>), typeof(...
And if you are using the generic base classes then specify your type with a `1:
<config type="Castle.ActiveRecord.Tests.Model.Test2ARBase`1, Castle.ActiveRecord.Tests">
Have a look at Multiple Database Test Case
and Test2ARBase![]()
Using Nullable Types
Include the following assembly references from the NHibernateContrib project:
- Nullables.dll
- Nullables.NHibernate.dll
ActiveRecord is able to check the property type and infer the nullable type handler. So, you may simply write:
[Property] public NullableDateTime CreatedDate { get { return _createdDate; } set { _createdDate = value; } } [Property] public NullableInt32 Count { get { return _count; } set { _count = value; } }
The nullable types are the following:
Nullable types and its handler classes
| CLR Basic Type | Nullable Type |
|---|---|
| System.Boolean | Nullables.NullableBoolean |
| System.Byte | Nullables.NullableByte |
| System.Char | Nullables.NullableChar |
| System.DateTime | Nullables.NullableDateTime |
| System.Decimal | Nullables.NullableDecimal |
| System.Double | Nullables.NullableDouble |
| System.Guid | Nullables.NullableGuid |
| System.Int16 | Nullables.NullableInt16 |
| System.Int32 | Nullables.NullableInt32 |
| System.Int64 | Nullables.NullableInt64 |
| System.SByte | Nullables.NullableSByte |
| System.Single | Nullables.NullableSingle |
