Version Attribute on Integer Field

Apr 15, 2010 at 2:35 AM

I am trying to use the version attribute on an “Account” object to auto increment the accountid property.  When I add the version attribute to the accountID property I am getting the error “Attribute (AccountID) does not exist”. when I remove the version attribute it will save the record correctly.  What am I doing wrong?

 

Thanks for your help!

 

    [DomainName("SCM_Account")]

    public class SDBAccount : DomainBase

    {

        public SDBAccount()

        {

            UniqueRowID = Guid.NewGuid();

            CreatedOn = DateTime.Now;

        }

 

        [ItemName]

        public Guid UniqueRowID { get; set; }

 

        [Version(VersioningBehavior.AutoIncrementAndConditionallyUpdate)]

        public int AccountID { get; set; }

 

        public string CompanyName { get; set; }

        public string Address1 { get; set; }

        public string Address2 { get; set; }

        public string City { get; set; }

        public string State { get; set; }

        public string Zip { get; set; }

 

        public string BusinessPhone { get; set; }

        public bool IsActive { get; set; }

 

        public DateTime ActiveDate { get; set; }

        public DateTime? InactiveDate { get; set; }

 

        public string BillingContactName { get; set; }

        public string BillingContactPhone { get; set; }

    }

Coordinator
Apr 15, 2010 at 3:18 AM

Are you trying to perform a conditional put or simply increment the accountID? A conditional put will cause the update to be rejected by SimpleDB if the stored value is not the expected value. To make this work your initial version value should be zero or null.

If you just want to auto-increment the AccountId use using VersioningBehavior.AutoIncrement. If you really do want to use conditional puts make sure your application never updates AccountId and that it starts with the correct initial value (zero or null).

Apr 16, 2010 at 12:23 AM

Thanks ashleytate for your response! I was trying only to auto-increment the accountid property so I changed the attribute to [VersioningBehavior.AutoIncrement] and it worked. This does lead me to another question, now when I set the AccountID property to 1 and save, it saves it as 10000000001. Is there a why I can have it set to 1 instead of 10000000001?

Coordinator
Apr 16, 2010 at 2:24 AM

You're welcome!

You may want to read up on the default formatting behavior here. SimpleDB stores everything as a string so you need padding and negative number offsets to allow lexicographical sorting and ranged queries. You can get the formatting you want by applying a custom format with the NumberFormatAttribute, using a custom format string with the CustomFormatAttribute, or possibly by making the version property an unsigned numeric type (an auto-incrementing version may not be compatible with other numeric types besides int, but you could try byte, ushort, or uint).