﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » .NET Forums » General .NET Discussion  » GUID Primekeys</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Sat, 19 Sep 2026 16:45:20 GMT</lastBuildDate><ttl>20</ttl><item><title>GUID Primekeys</title><link>http://forum.strataframe.net/FindPost8476.aspx</link><description>I have an app developing that will include several wireless handheld barcode scanners running SQL Mobile, operating simultaneously alongside a winforms component. I am using SQL merge replication and RDA and like the concepts and implementation so far.&lt;br&gt;
&lt;br&gt;
Now this works best with GUID primekeys so they are guaranteed to be unique across replicated copies of the tables on the handhelds.&lt;br&gt;
&lt;br&gt;
So the question is this, any tricks or "things to know" when using GUID primekeys versus integers (as I have always used) in the framework? Do you recommend the default value of newid() ?&lt;br&gt;
&lt;br&gt;
As always thanks for the insight.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;</description><pubDate>Tue, 01 May 2007 13:02:00 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: GUID Primekeys</title><link>http://forum.strataframe.net/FindPost8623.aspx</link><description>We will add it to the list, Keith. ;)</description><pubDate>Tue, 01 May 2007 13:02:00 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: GUID Primekeys</title><link>http://forum.strataframe.net/FindPost8616.aspx</link><description>I wrote in BIG RED LETTERING on my deployment notes to remember to set the ROWGUID property on my deployment server at the customers site. Well as you can guess, I forgot so nothing worked for a while and I looked silly :D&lt;br&gt;
&lt;br&gt;
There are other "advanced" field properties related to SQL merge and RDA replication that cannot be set via the DDT, if they could in the future that would be great.&lt;br&gt;
&lt;br&gt;
Thank you.&lt;br&gt;</description><pubDate>Tue, 01 May 2007 11:04:25 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: GUID Primekeys</title><link>http://forum.strataframe.net/FindPost8531.aspx</link><description>OK thanks Ben.</description><pubDate>Thu, 26 Apr 2007 09:14:55 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: GUID Primekeys</title><link>http://forum.strataframe.net/FindPost8529.aspx</link><description>Actually, the DDT does not have the functionality for you to set the RowGuid option on a column.&amp;nbsp; It's a pending feature request, but it has not been implemented.</description><pubDate>Thu, 26 Apr 2007 08:48:57 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: GUID Primekeys</title><link>http://forum.strataframe.net/FindPost8528.aspx</link><description>/shameless bump</description><pubDate>Thu, 26 Apr 2007 08:26:36 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: GUID Primekeys</title><link>http://forum.strataframe.net/FindPost8498.aspx</link><description>SQL merge replication creates the GUID primekeys for me when merging in new rows to the "publisher" database so no worries there.&lt;br&gt;
&lt;br&gt;
One follow up question, I got this all working but had to specify the GUID primekey column as ROWGUID = YES on the field definition, I had to set it manually via SQL Management console because I couldnt find that setting in DDT, is there an advance button I am missing somewhere or another way to set "advance field properties"? &lt;br&gt;
&lt;br&gt;
Ideally (in my brain at least) everything should be defined in the DDT and not require any "tweaking" upon deployment.&lt;br&gt;
&lt;br&gt;
Thanks.</description><pubDate>Wed, 25 Apr 2007 11:38:28 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: GUID Primekeys</title><link>http://forum.strataframe.net/FindPost8494.aspx</link><description>I am using Guids as for&amp;nbsp;my PK as&amp;nbsp;well.&amp;nbsp;I used the approach of overriding the set Default values in&amp;nbsp;my subclassed Bas Biz object as below.&amp;nbsp;I also call out to a function that returns a sequential guid that is&amp;nbsp;similiar the NewSequentialId() function in SQL 2005 but you can replace&amp;nbsp;"BoCommon.NewSeqGuid" with "&lt;FONT size=2&gt;Guid.NewGuid()"l.&lt;/FONT&gt;. Here is a link to an very informative artice about guids as pk's and the benefit of using sequential ID's&amp;nbsp;&lt;P&gt;[url]http://www.informit.com/articles/article.asp?p=25862&amp;amp;rl=1[/url]&lt;/P&gt;&lt;P&gt;&amp;nbsp;[codesnippet]&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;Protected&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Overrides&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; OnSetDefaultValues()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;MyBase&lt;/FONT&gt;&lt;FONT size=2&gt;.OnSetDefaultValues()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'Set Value for GUID PK&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'Get Reference To Primary Key Field Property&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; LoPkField &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; Reflection.PropertyInfo = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.GetType.GetProperty(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.PrimaryKeyField)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'If the PK is a Guid Generate a Sequential GUID to prevent Index fragmentation&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/FONT&gt;&lt;FONT size=2&gt; LoPkField.PropertyType &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Is&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;GetType&lt;/FONT&gt;&lt;FONT size=2&gt;(System.Guid) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;LoPkField.SetValue(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;, BoCommon.NewSeqGuid, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Nothing&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'Set Value for Location Code&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.PopulateLocationCode &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; LoLocation &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; Reflection.PropertyInfo = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.GetType.GetProperty(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"LOCNCODE"&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;LoLocation.SetValue(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;,Payroll.Common.LocationCode, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Nothing&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;[/codesnippet]</description><pubDate>Wed, 25 Apr 2007 10:48:10 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item><item><title>RE: GUID Primekeys</title><link>http://forum.strataframe.net/FindPost8489.aspx</link><description>There are a few caveats for sure :)&lt;P&gt;First, if you want to use NewID() within SQL, you will have to create stored procedures for the INSERTs and configure the business objects to use them.&amp;nbsp; The reason is that there is no method like SCOPE_IDENTITY() within SQL Server that will return the last created NewID().&amp;nbsp; So, at the top of the sproc, you need to call NewID() and place it into the output parameter specified for the PK.&amp;nbsp; Then, you need to insert the record.&lt;/P&gt;&lt;P&gt;There is another option for GUIDs, and that is to use System.Guid.NewGuid() to create your Guids.&amp;nbsp; You can put the call within the SetDefaultValues() of the business object.&amp;nbsp; While you could technically get a duplication by letting each client create its own PKs, the MAC address of the computer is figured into creating the GUIDs (to help keep them unique since MAC addresses are unique) and you have a better chance of being struck by lightning, stung by a bee, and attached by a shark at the same time than you do of getting a duplicate GUID.&amp;nbsp; &lt;/P&gt;&lt;P&gt;So, either use sprocs for your INSERTs for the BOs or use the System.Guid.NewGuid().&amp;nbsp; Either way, there's not really any downside to using GUIDs for PKs (other than if you look at the database, an integer is easier to read than 32digit number with dashes ;))</description><pubDate>Wed, 25 Apr 2007 09:25:25 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item></channel></rss>