in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

How to: Create an identity field that is not a primary key

Last post 11/18/2008 12:47 PM by Kelly Wilkerson. 4 replies.
Page 1 of 1 (5 items)
Sort Posts:
Previous Next
  • 7/27/2008 12:57 PM

    How to: Create an identity field that is not a primary key

    I need to have a property auto-generated but it is not a primary key.

    How do I accomplish this using Xpo? 

    Martin Mizzell
    martinmizzell@att.net

    "Knowing is half the battle..." - G.I. Joe
  • 7/29/2008 2:13 PM In reply to

    Re: How to: Create an identity field that is not a primary key

     Great...and thanks. Glad we could all have this talk.

    Martin Mizzell
    martinmizzell@att.net

    "Knowing is half the battle..." - G.I. Joe
  • 7/29/2008 2:20 PM In reply to

    Re: How to: Create an identity field that is not a primary key

    I don't know whether I understand what you really want, but you can do this in your own base class.
     
    regards, Robert
     
  • 7/29/2008 2:29 PM In reply to

    Re: How to: Create an identity field that is not a primary key

     Currently, to mark a property as a primary key we use the Key attribute. If we need that field to be auto-generated, we just pass true into the attribute's constructor, right? What about when we need a property to be auto-generated but it cannot be marked as the primary key? Do I have to create my own attribute for this?

    Someone might look at the post and say, "What the hell do you want to do that for?" The answer is simple, I don't. However, I am using Xpo to work with an existing database schema that I cannot change.

    Any insight would be most appreciated...

    Martin Mizzell
    martinmizzell@att.net

    "Knowing is half the battle..." - G.I. Joe
  • 11/18/2008 12:47 PM In reply to

    Re: How to: Create an identity field that is not a primary key

     Hey Martin,

    I recently ran into a situation where I have a Comment BO that should show the comments in the order in which they where entered.  I created an Int64 field in the BO and marked it using the [NonPersistent] attribute.  Then set the field in SQL Server as an Identity with a seed of 1 and increment of 1.  This seems to work well (the comments appear in the correct order when performing a Select from SQL Server query); however, the XAF listview for the Comment object returns '0' for the value - I guess because it is marked with the [NonPersistent] attribute.

    I have set the Comments_ListView to sort descending so the most current comments are listed first, but since the field returns '0' for every record, it does not sort (of course).  Is there a way to persist these comments in a way that preserves the order?  I even tried it without the attribute and removed the setter, but it still returns '0' for the identity field.  I thought about using the entered date and sorting that way, but what about comments entered the same day - only the dates are stored in the table, not date and time.

    Did you ever figure out anything concerning this or find information somewhere that you can share?  Anybody else have this requirement that can help?

    Thanks,

    Kelly.

     

    - Abandonned - I just removed the int64 field that I had set as an identity field from the Comment BO.  Too little documentation exists to try and figure out how to make it work.  Instead, I am just writing DateTime.Now to the EntryDate field instead of DateTime.Today.  Since SQL Server stores the time down to .001 seconds, I figure that should be enough to determine the order in which the comments are entered.  But, I can see a need for a non-key identity field.  I like to use GUID's for primary keys and INT identity fields to preserve an order.  Kelly.

Page 1 of 1 (5 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED