Updatable Primary Key problem


Author
Message
Aaron Young
Aaron Young
Advanced StrataFrame User (569 reputation)Advanced StrataFrame User (569 reputation)Advanced StrataFrame User (569 reputation)Advanced StrataFrame User (569 reputation)Advanced StrataFrame User (569 reputation)Advanced StrataFrame User (569 reputation)Advanced StrataFrame User (569 reputation)Advanced StrataFrame User (569 reputation)Advanced StrataFrame User (569 reputation)
Group: StrataFrame Users
Posts: 277, Visits: 1.1K
I want to set my own value for primary keys but the BO.Save() method doesn't write the primary key back to the database.

For example, I have an Int32 primary key called "CustomerID" and I set the value in SetDefaultValues() and the value is unique. I call BO.Add() which sets the value of CustomerID. I check the value of BO.CustomerID and it is correctly set to a valid value. However, when I do BO.Save() the CustomerID field is not written back to the SQL database (I can see this in SQL Profiler).

I have tried setting PrimaryKeyIsUpdatable to true but I guess I haven't done it correctly as Save() never writes the primary key.

Can anyone help?

Thanks in advance.

Replies
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Paul Chase (04/24/2008)
Here is some logic I have in my base class BO to assign the PK which may help you out if you haven't added it yet.

Hi Paul,

Thanks for the code must appreciated.  Of course I did not have it since I am currently not using GUID for the current project, but yes, I will use it. Hehe

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
One word of caution, if you are not planning on using replication you should not use GUID primary keys!  They create a lot of additional overhead and dramatically slow down queries on the SQL side versus an integer value.  So if you are planning on your databases getting very large, then I would highly recommend against using a GUID.  There is definintely a time and place for GUIDs and Paul's application is one of those, but if you are creating GUIDs just to create a GUIDs PK, then I would strongly recommnend against doing this.  We have been spending a lot of time in T-SQL lately and working on very complex queries and tracing execution paths...when you have a GUID as a primary key versus an integer, especially on a large database, the query can execute as much as 100 times slower (yes times, not percent).  A query that took 300 ms went to 3 ms.  So as the database becomes much larger and this same query took 1 second it would go from being 1 second to 10 ms.  This is a huge difference!

By taking this type of logic into account, we turned a query taking 4.5 seconds the other day on a very large database into 22 ms....that was a happy day BigGrin  We made an even larger impact when dealing with dates.  Instead of storing these fields that we will be testing on with >= or <= as a date, we stored them as ticks in a BigInt field.  This was the largest change in performance that we had seen thus far.  Databases deal with integer data better than strings when it comes to performance and parameters.  You won't have as large a hit on a PK field, but you don't want to box yourself into a corner either.

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Thanks Trent, points taken.Hehe

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Aaron Young - 17 Years Ago
Aaron Young - 17 Years Ago
Aaron Young - 17 Years Ago
Bill Cunnien - 17 Years Ago
Paul Chase - 17 Years Ago
                         [quote][b]Paul Chase (04/24/2008)[/b][hr] I hope that helps am makes...
Edhy Rijo - 17 Years Ago
                             Hi edhy, Guids as primekeys work fine with SF. The issue I had was...
Paul Chase - 17 Years Ago
                                 [quote]Is there a table or primary key property in the DDT that sets...
Trent L. Taylor - 17 Years Ago
                                 [quote][b]Paul Chase (04/24/2008)[/b][hr]Here issome logicI havein my...
Edhy Rijo - 17 Years Ago
                                     One word of caution, if you are not planning on using replication you...
Trent L. Taylor - 17 Years Ago
                                         Thanks Trent, points taken.:hehe:
Edhy Rijo - 17 Years Ago
Charles R Hankey - 17 Years Ago
Trent L. Taylor - 17 Years Ago
Aaron Young - 17 Years Ago
Trent L. Taylor - 17 Years Ago
                         I think you are right Trent. Whatever way we have tried toengineer it,...
Aaron Young - 17 Years Ago
Edhy Rijo - 17 Years Ago
                         Hi Edhy, That is good to know. We have tested with GUIDs to a limited...
Aaron Young - 17 Years Ago
                             Guys, If youwant to use GUID's then you definately will want to...
Paul Chase - 17 Years Ago
                                 [quote][b]Paul Chase (04/25/2008)[/b][hr]I now use Sqlmerge...
Edhy Rijo - 17 Years Ago
                                     Edhy, Here is a step-by-step on setting up Merge Replication. Just...
Trent L. Taylor - 17 Years Ago
                                         Great! Thanks Trent.
Edhy Rijo - 17 Years Ago
                                             Like Trent said there area tonof articles explaining the different...
Paul Chase - 17 Years Ago
                                                 One consequence of using any form of replication is future changes to...
Aaron Young - 17 Years Ago
                                 Today I started to implement GUID PK for a new SF project, and this...
Edhy Rijo - 17 Years Ago
Peter Jones - 17 Years Ago
Aaron Young - 17 Years Ago
Edhy Rijo - 17 Years Ago
Trent L. Taylor - 17 Years Ago
                         Aaron, If you have an application that is going to replicate it would...
Paul Chase - 17 Years Ago
Aaron Young - 17 Years Ago
Trent L. Taylor - 17 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search