[SOLVED] Compound primary keys and Delete method

Posts   
 
    
bonder
User
Posts: 36
Joined: 23-Sep-2003
# Posted on: 18-Feb-2004 18:19:19   

This is from one of my developers:

There is the problem in generation entity class for entity that has composite primary key.

There are now constructors that have as parameters all fields of primary key in this case.

But most annoying thing that Delete() method of generated class Delete more than one entity from BD,

more precisely, all entities, that have in its keys field same value, as in deleted entity.

Example:

Table called SubTypeSubscription ClientID (int PK, not null) TypeID (int PK, not null)

Rows in table:

ClientId TypeID

1 2 1 22 1 345

Code:


int clientId;
SubTypeSubscription subscription = new SubTypeSubscription(clientId);
Subscription.Delete();

Execution of this code delete all rows in table SubTypeSubscription.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 18-Feb-2004 18:56:55   

I'm a bit confused, as an entity with say 2 fields in its PK, has a constructor with 2 fields, so you have to specify both. So I wonder how your code snippet can compile as you specify just 1 PK field. confused

A delete will always construct a filter with ALL PK fields. All those fields are compared to the value they have in teh entity to delete. So in your case, the TypeID field will have the value 0, so the delete statement will look like:

DELETE FROM SubTypeSubscription WHERE ClientID = paramClientID AND TypeID = paramTypeID

if I'm not mistaken you use Oracle, so I didn't use sqlserver syntaxis. paramClientID will be set to 0 with your example (default value of int) and TypeID will also be 0.

This will thus delete 0 rows.

Please, correct me where I go wrong simple_smile so I can jump into the code and check what should have been there and what is actually there.

Frans Bouma | Lead developer LLBLGen Pro
bonder
User
Posts: 36
Joined: 23-Sep-2003
# Posted on: 19-Feb-2004 16:00:02   

Frans, I am going to send you a piece of DDL and some generated files to show you the issue a bit more. Hopefully it's just that we're doing something wrong, which would be great news! simple_smile

And no, we are using SQL Server, sorry I didn't explain that.

--Bruce

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 19-Feb-2004 16:24:34   

Ok, send it to support@llblgen.com and I'll look into it. simple_smile I'll mail you when I've received it.

Frans Bouma | Lead developer LLBLGen Pro