The Darkside

Shedding light on things and stuff

 
  Home :: Contact :: Syndication  :: Login
  87 Posts :: 0 Stories :: 56 Comments :: 2 Trackbacks

Ads

 

Donate via PayPal...

...if you feel the site helped.

Archives

Post Categories

Open Source Projects

Other Blogs

Configuration

Version 3 now supports the short-hand configuration options supplied by NHibernate. You choose the DB type, supply a connection string name, and the rest of the defaults are chosen for you.

  <configSections>

    <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord"/>

  </configSections>

  <connectionStrings>

    <add name="ARTest" connectionString="Server=(local); Database=ComplexDBTest; Integrated Security=SSPI"/>

  </connectionStrings>

  <activerecord>

    <config db="MsSqlServer2005" csn="ARTest"/>

  </activerecord>

SessionScope-less Lazy Loading

This is a great change that’s been implemented. The code example below (very contrived, I know, but demonstrates the point) used to throw an exception, but doesn’t anymore.

    [ActiveRecord("Person", Lazy = true)]

    public partial class Person : ActiveRecordBase<Person>

    {

        [PrimaryKey(Generator = PrimaryKeyType.GuidComb, Column = "PersonId")]

        public virtual Guid Id { get; set; }

 

        [HasMany(typeof(ContactNumber), Table = "ContactNumbers", ColumnKey = "PersonId", Lazy = true)]

        public virtual IList<ContactNumber> PersonIdContactNumbersList { get; set; }

    }

 

    [ActiveRecord("ContactNumber")]

    public partial class ContactNumber : ActiveRecordBase<ContactNumber>

    {

        [PrimaryKey(Generator = PrimaryKeyType.GuidComb, Column = "ContactNumberId")]

        public virtual Guid Id { get; set; }

 

        [BelongsTo(Type = typeof(Person), Column = "PersonId")]

        public virtual Person Person { get; set; }

    }

 

    public class Program

    {

        static void Main(string[] args)

        {

            ActiveRecordStarter.Initialize(Assembly.GetExecutingAssembly(), ActiveRecordSectionHandler.Instance);

 

 

            ContactNumber contactNumber;

            using (new SessionScope())

            {

                contactNumber = ContactNumber.FindFirst(Order.Asc("Id"));

            }

            Debug.WriteLine(contactNumber.Person.Id); //Used to throw an exception

        }

    }

Make sure that in your configuration, (if you’re still specifying the entire config) you’re using the Castle.ActiveRecord.ByteCode.ProxyFactoryFactory proxy factory.

 

Lazy Loading of Blob Properties

You can now use the “Lazy” keyword on blob properties which tells NHibernate not to include this column in the select statement, but only call it when it’s explicitly used. Some notes on this, though:

  • If you have more than one column marked as lazy, they are ALL fetched when you access the first one.
  • The property should be an auto-prop
  • This results in and extra select being fired off when you used this column – it may end up being a problem in large sets of data.

The syntax is straight forward:

        [Property (Column ="Data", ColumnType = "BinaryBlob" , Lazy = true)]

        public virtual byte[] Data { get; set; }

 

LINQ

LINQ support is now rolled into the Castle ActiveRecord assembly, and doesn’t require a reference to another file.

 

SessionScopeWebModule (Breaking Change)

This has been removed from the main Castle ActiveRecord assembly and is now in the assembly Castle.ActiveRecord.Web.dll. You’ll need to update your configuration for the HttpModule as follows:

    <httpModules>

      <add name="ARScope" type="Castle.ActiveRecord.Framework.SessionScopeWebModule, Castle.ActiveRecord.Web"/>

    </httpModules>

posted on Wednesday, March 30, 2011 12:37 PM

Feedback

# re: What’s new in Castle ActiveRecord 3 RC? 4/15/2011 7:02 PM Larry
Nice insight to the Castle AR version 3.

Most inspiring part is SessionScope-less Lazy Loading.



Comments have been closed on this topic.