StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Primary Keys in StrataFrame/SQL Server 2005Expand / Collapse
Author
Message
Posted 03/05/2006 11:19:46 PM
StrataFrame Beginner

StrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame Beginner

Group: Forum Members
Last Login: 01/29/2007 12:10:55 AM
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?

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.

Post #589
Posted 03/06/2006 9:44:25 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 10/21/2008 9:20:58 AM
Posts: 2,685, Visits: 1,887
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.


www.bungie.net
Post #590
Posted 03/06/2006 11:30:56 PM
StrataFrame Beginner

StrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame Beginner

Group: Forum Members
Last Login: 01/29/2007 12:10:55 AM
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!

Lance

Post #591
Posted 03/07/2006 8:46:26 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 10/21/2008 9:20:58 AM
Posts: 2,685, Visits: 1,887
No problem

That's what we're here for...


www.bungie.net
Post #592
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 2:36am

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.063. 10 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.