Dashboard > ActiveRecord > ... > Documentation > Advanced usage
Log In   View a printable version of the current page.
Advanced usage
Added by Daniel Rothmaler, last edited by Josh Rivers on Sep 23, 2007  (view change)
Labels: 
(None)


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

Site running on a free Atlassian Confluence Community License granted to Castle Project. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators