XPO

July 2011 - Posts

  • XPO–11.2 Sneak Peek - Auto-generated Int64 keys

    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

LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2017 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners