Monday, June 06, 2005

[Opf3] New mapping engine

We created a new mapping engine for Opf3. From the point of view of the developers using Opf3 nothing changes. Under the hood we made a lot changes. Opf3 does now also allow to override mapped properties without setting the FieldAttribute again. For example:


[Persistent("FOO")]
public class Foo
{
   private string _bar;

   [Field("BAR")]
   public virtual string Bar
   {
      get { return _bar; }
      set { _bar = value; }
   }
}

public class Foo1 : Foo
{
   public override string Bar
   {
      get { return base.Bar; }
      set
      {
         if (value == null)
            throw new Exception("Not valid.");
      }
   }
}

// Other code.

// Load the first object of Foo1.
// The overriden Bar is populated as the FieldAttribute
// on the property in the base class counts.
Foo1 foo = context.GetObject<Foo1>();


To map the override property to another field simply set the FieldAttribute on the ovverriden property. The new FieldAttribute overrides the one of the base property.

As another feature the new mapping engine allows also to map fields to fields in the storage.


[Persistent("FOO")]
public class Foo
{
   [Field("BAR")]
   public string Bar;
}


The new engine will go online with the next release of Opf3.

0 Comments:

Post a Comment

<< Home