Request for Primary Key Generation example


Author
Message
Rory Sawtelle
Rory Sawtelle
StrataFrame Beginner (1 reputation)StrataFrame Beginner (1 reputation)StrataFrame Beginner (1 reputation)StrataFrame Beginner (1 reputation)StrataFrame Beginner (1 reputation)StrataFrame Beginner (1 reputation)StrataFrame Beginner (1 reputation)StrataFrame Beginner (1 reputation)StrataFrame Beginner (1 reputation)
Group: StrataFrame Users
Posts: 1, Visits: 72
Hi,

Iam working with the trial version of Strataframe and am attempting to get asimple VS 2008 C# CRUD proof of concept test application functioning for SybaseSQL Anywhere 11. I am almost there, navigation and edits work fine - but Ican't seem to discover the correct method for primary key generation tofacilitate a successful insert. The default behavior of the BO is expecting an autogenerated primary key Id which is not the methodology we are using. I am usinga key table with a simple key id field that is programmatically incrementedwith each new insert. I see properties in the BO on my form that seem toindicate that independent primary key generation is supported but I have notbeen able to find a closed loop example that shows/discusses the BO setup andform controls and related properties and possible custom procedures necessaryto implement this.

Isthere an example, or a forum thread or something in the documentation that Ihave missed that covers this?

Anyinformation would be helpful.

Thanks,

RorySawtelle


Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Rory.

When I need a simple Primary Key , I set the AutoIncrement in Sql Server and this works without having to do anything else. When I have a need for a Unique Key that must be unique but cannot be a standard 'PrimaryKey' I use a Special 'UniqueTable' tbale set up in the datatbase which has 3 columns:

UNI_PK   Unique key of the UNIQUE Table

UNI_NAME    A link to a unique Key I want to generate (e.g. INVNUM   ORDERNUM   DESPATCHNUM   etc)

UNI_PREVKEY    The Most recent Key that was used for UNI_NAME

I then have a Method set up , which I call, and it returns the next available unique key

public static int GenerateUniqueKey(string myName)
{
MicroFour.StrataFrame.Business.BusinessLayer.TransactionBegin("", IsolationLevel.Serializable);
UniBO bo = new UniBO();
bo.UniFillByTable(myName);
if (bo.Count == 0)
{
bo.Add();
bo.UNI_NAME = myName;
bo.UNI_PREVKEY = 1;
}
else
{
bo.UNI_PREVKEY = bo.UNI_PREVKEY + 1;
}
bo.Save(true);
MicroFour.StrataFrame.Business.BusinessLayer.TransactionCommit("");
return bo.UNI_PREVKEY;
} // GenerateUniqueKey (Cannot have more than one Identity Key in SqlServer


 

There are probabaly other ways of doing this also, but this is what I have settled on

Regards,

Gerard

 




Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Rory,

Rory Sawtelle (1/2/2012)
Isthere an example, or a forum thread or something in the documentation that Ihave missed that covers this?


As you are guessing SF Business Object do support handling your own PK generation.  Basically to bypass default behavior simply set the BO properties PrimaryKeyIsAutoIncremented = False and PrimaryKeyIsUpdatable = True, if you are using a base BO class (which everybody should) then you can set this in the base class otherwise you can do it in the instance in your forms or via code.

Also it is a good idea to look at all the properties of the BO, their descriptions and the help file to grasp all the control the developers have over how the BO should work for each application.

Ger, thanks for the sample, I used to use that technique a while back when working with Visual FoxPro, now what I do is simply get the MAX(FieldName) + 1 for simpler process where not too many users will be working at the same time.

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search