Primary Keys in StrataFrame/SQL Server 2005


Author
Message
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
No problem Smile



That's what we're here for...
Lance Tofsrud
Lance Tofsrud
StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)
Group: Forum Members
Posts: 12, Visits: 21
Thanks for the quick reply Ben.

I set the IsIdentity property to True, the Identity Increment to 1 and the Identity Seed to 1 and finally managed to get it working.  I think I may have messed up some of my properties on my business object too so I decided to throw everything out the window and re-spiked it.

Thanks again! BigGrin

Lance

StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Hi Lance,



Yes, when you set the PrimaryKeyIsAutoIncremented property to True on the business object, the business object assumes that the value will be assigned by the server, and it needs to retrieve the new value after the record is inserted. Also, since the PK value will be assigned by the server, the business object passes a NULL value for the PK value to tell the server to assign the value. What you need to do is this:



Integer PK -- Auto Incremented:



Set your PK to an integer type and configure the IDENTITY property on the table to be the same column as the PK. When the business object inserts a NULL value for the PK, the server will automatically assign a new identity (auto-incremented) value for the record.



GUID PK -- Auto Assigned:



Set your PK to a unique identifier and configure the column's default value to be (NEWID()). When the business object inserts a NULL value for the PK, the server will create a new GUID and assign it to the column.



PrimaryKeyIsAutoIncremented = False



When you set the PrimaryKeyIsAutoIncremented property to False, it means that the value will not be assigned by the server, and you will need to manually assign a new value for the primary key on the business object's record before saving. You may have some method that automatically gets a new integer value for the PK or gets a new GUID, and you can use this method to assign the PK value to the record within the SetDefaultValues event handler.



Generally, you only want to set the PrimaryKeyIsAutoIncremented property to False if you're working with a supertable/subtable relationship and you already know the primary key value for the subtable.
Lance Tofsrud
Lance Tofsrud
StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)
Group: Forum Members
Posts: 12, Visits: 21
Hi everyone,

I have finally managed to set aside some time to review StrataFrame and I am getting somewhat frustrated on how StrataFrame handles inserts; more specifically on handling the primary key.

I have tried setting the Primary Key in SQL Server as a uniqueidentifier and then setting the PrimaryKeyIsAutoIncremented property to False.

I have tried setting the Primary Key in SQL Server as an integer while leaving the primary key to be auto-incremented (Same property as above on the object's property).

I keep getting the error indicating that it cannot insert NULL into my primary key column; therefore the save fails. I have tried to recreate the business object and I am unsure why it is trying to jam a number into that field.

Is there a recommended way for setting up PKs in SQL Server and StrataFrame?Unsure

Thanks!

Lance

BusinessLayerException
 An error occurred while saving an the data to the server.


DataLayerSavingException
 Cannot insert the value NULL into column 'StockIdentifier', table 'ObserverTest.dbo.Stocks'; column does not allow nulls. INSERT fails.
Operand type clash: uniqueidentifier is incompatible with numeric
The statement has been terminated.


SqlException
 Cannot insert the value NULL into column 'StockIdentifier', table 'ObserverTest.dbo.Stocks'; column does not allow nulls. INSERT fails.
Operand type clash: uniqueidentifier is incompatible with numeric
The statement has been terminated.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search