Ticket CQ22273
Visible to All Users

Auto generated sequence numbers

created 18 years ago

Is there a facility or best practice for generating ascending human-readable sequence numbers for entities such as Order.OrderNumber (i.e. each saved order gets the next available order number)?
Thanks,
Jascha

Comments (2)
DevExpress Support Team 18 years ago

    Hello Jascha,
    It's best to define a special field/property which can be seen and used by the users of your application to identify business objects (documents). You will need to use the Session.FindObject method to obtain an object by a user-friendly ID. To optimize searching for objects, declare the ID field with the Indexed attribute. Here is some sample code:

    C#
    using DevExpress.Xpo; // Object with a user-friendly ID public class Client : XPObject { [Indexed(Unique=true)] public string ClientID; ... } // Add object Client client = new Client(); client.ClientID = "A007"; client.Save(); // Get object Client GetClientById(string clientID) { return Session.DefaultSession.FindObject(typeof(Client), new BinaryOperator("ClientID", clientID)) as Client; } Client client = GetClientById("A007"); Console.WriteLine(client == null ? "Client not found" : client.ClientID);

    Please note that you will need to develop your own algorithm for generating unique values for user-friendly IDs. The attached project shows our solution to this task. Hopefully, it will come in handy.
    Thank you,
    Nick

    Dennis Garavsky (DevExpress) 16 years ago

      Hi Guys,
      Please check the following issue in the Support Center: ID Q130688 (CQ22273 - ( Auto generated sequence numbers ) - how does this work?) in case of any questions on how to use helper classes from this example.
      Thanks,
      Dennis

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.