Question about GetIdValue()Question about GetIdValue()
Old forum URL: forums.lhotka.net/forums/t/382.aspx
supercodepoet posted on Thursday, June 15, 2006
We come from the camp that you have an identity primary key for your
table that acts as an Id and then an unqiue constrant on your natural
primary key of the data. When setting up your primary key fields for
business objects using CLSA.NET, do you use the identity key, the
nautral key or a combination of both? I can see having the Id field for
the real primary key and the GetIdValue() method return a combination
of the natural primary key for Equals() operations. In this case which
fields do you mark with the System.ComponentModel.DataObjectField(true,
true) attribute so data binding will work properly?
Thanks,
TravisLayeredDev replied on Thursday, June 15, 2006
Hi Travis,
I come from the same camp. I don't have much experience with .net CSLA though I have worked extensively on VB6 CSLA. And since no one has replied to your post, I will just try.
From my experience the GetIdValue should just return the real primary key. i.e. the identity primary key.
When a client application tries to add a record with a duplicate in the natural key, you can throw an exception which will be caught by the client application.
Cosmic Ovungal
ajj3085 replied on Thursday, June 15, 2006
This is what I am doing as well. The only cavet is for new objects, which don't yet have a primary key.
This will happen usually in a DataGridView; if all your new objects use -1 for the un-intialized primary key, asking the grid to remove a row will simply remove the first object it finds with that Id value, NOT the one you selected.
The work around is to have a static int in your BO class, which starts at -1. New objects get that value and subtract one, so the next new object will have -2. This allows the grid to work as expected.
HTH
Andy
guyroch replied on Thursday, June 15, 2006
Some even go as far as always returning a System.Guid.NewGuid() with
the GetIsValue() and treat and primary keys and other unique keys as
any other business properties inside the business object.
However, I don't think it makes that much difference if you use the
real PK or another UK, I'm using the real PK myself - the identity
column in this case. It just need to be unique.
Copyright (c) Marimer LLC