XPO–11.2 Sneak Peek - Auto-generated Int64 keys

XPO Team Blog
28 July 2011

We are not far from 11.1 and I presume that you will be surprised to see 11.2 sneak peeks at this timeSmile

There is not actually not much to say here, because the subject says it all. Starting from version 11.2 you can define a Int64 (long) key property in your class and mark it with the KeyAttribute, whose AutoGenerate parameter will be set to True:

  1: [NonPersistent, MemberDesignTimeVisibility(false)]
  2: public abstract class XPObjectWithInt64Key : XPCustomObject {
  3:     ...
  4:     Int64 _oid = -1;
  5:     [Persistent("OID"), Key(AutoGenerate = true)]
  6:     public Int64 Oid {
  7:         get { return _oid; }
  8:         set {
  9:             Int64 oldValue = Oid;
 10:             if (oldValue == value) return;
 11:             _oid = value;
 12:             OnChanged("Oid", oldValue, value);
 13:         }
 14:     }
 15:     ...
 16: }
 17: public class TestPerson : XPObjectWithInt64Key {
 18:     public TestPerson(Session session)
 19:         : base(session) { }
 20:     private string firstName;
 21:     public string FirstName {
 22:         get { return firstName; }
 23:         set { SetPropertyValue("FirstName", ref firstName, value); }
 24:     }
 25:     private string lastName;
 26:     public string LastName {
 27:         get { return lastName; }
 28:         set { SetPropertyValue("LastName", ref lastName, value); }
 29:     }
 30: }

Interested readers will notice that for my base persistent class I grabbed the source code from the standard XPObject class and then just changed its key type from Int32 to Int64.

Well, if you now create and save a new object, a key will be automatically generated for it:

screenshot

I hope you like this small addition to XPO, because it provides you with more flexibility (previously auto generation was supported only for Int32 and Guid keys).

Please let us know your thoughts on this.

Happy XPOingWinking smile

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.