Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using GUID as PrimaryKey
Message
 
À
10/08/2006 09:02:00
Jeff Corder
Ambit Technologies, LLC
Missouri, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01144358
Message ID:
01144678
Vues:
13
Thank you very much.
Regards
>I put some code in the Business.cs file under the HookSetDefaultValues() method to set the Guids. The code steps through the dataset to find the Guid (the first record in my data). The only problem is that if there are default values for the table, it overrides the HookSetDefaultValues() in the business object and does not call the base function. I add base.HookSetDefaultValues(dataRow) and everything works fine.
>
>
>
> protected override void HookSetDefaultValues(DataRow dataRow)
> { // We need to make sure the Guids are not null
> base.HookSetDefaultValues(dataRow);
>
> for (int iCol = 0; iCol < dataRow.Table.Columns.Count; iCol++)
> {
> if (dataRow.Table.Columns[iCol].DataType.ToString() == "System.Guid"
> && !(dataRow[iCol] is Guid))
> {
> if (dataRow.Table.Columns[iCol].ColumnName == this.PrimaryKey)
> { // This is as good a place to assign the primary key as any
> dataRow[iCol] = Guid.NewGuid();
> break;
> }
> }
> }
> }
>
>Jeff
Fred Besterwitch, MCP

The harder you work. The luckier you get.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform