New Posts New Posts RSS Feed: must have a primary key on table when inserting ?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

must have a primary key on table when inserting ?

 Post Reply Post Reply
Author
sanselmo View Drop Down
Newbie
Newbie
Avatar

Joined: 09-Nov-2007
Location: Canada
Posts: 7
Post Options Post Options   Quote sanselmo Quote  Post ReplyReply Direct Link To This Post Topic: must have a primary key on table when inserting ?
    Posted: 09-Feb-2009 at 7:46am
Thanks all...
 
I was assigned to another project...
 
I will try adding keys on the object mapper as mentionned above...
 
seb
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 06-Feb-2009 at 10:50am

You don't need to modify the database at all to make this work.  As David stated, you can form a unique key out of the first two columns in Table_Link - and you can do this directly in the Object Mapper.  DevForce needs every entity to have "identity", but that doesn't mean you must strictly mirror primary keys in the database.  If your table doesn't have a primary key, DevForce, via the Object Mapper, will allow you to specify the columns that DevForce will use to enforce "identity" on the entity.  So in your case, open the Object Mapper, and on the "Simple Properties" tab for this entity check off these two properties as "Key" properties. 

Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 05-Feb-2009 at 7:59am

What is wrong with wrong with using the combined two columns as the priary key?  You don't have to add a column, you just have a multi-part key.



Edited by davidklitzke - 05-Feb-2009 at 8:01am
Back to Top
sanselmo View Drop Down
Newbie
Newbie
Avatar

Joined: 09-Nov-2007
Location: Canada
Posts: 7
Post Options Post Options   Quote sanselmo Quote  Post ReplyReply Direct Link To This Post Posted: 05-Feb-2009 at 5:03am
Thanks for the answers... but I'm not that happy about it.
 
My tasks was to copy/reproduce a part of a software (made in VB6) without changing the database and using DevForce.
 
And the old software is still working on this DB so I can't change the structure of a table.
 
Do you see a solution?
 
seb
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 04-Feb-2009 at 7:52pm
Every entity that is inserted into the Persistence Manager cache must have a primary key.  Best practice for a linking table is to use a third column for the primary key.  For example, it could be an Identity column, GUID, or BigInt from IdeaBlade IIdGenerator.
Back to Top
*Calsy View Drop Down
Groupie
Groupie


Joined: 02-Feb-2009
Location: Australia
Posts: 69
Post Options Post Options   Quote *Calsy Quote  Post ReplyReply Direct Link To This Post Posted: 04-Feb-2009 at 2:00pm
Hi Seb, Could you not just put an Autonumber (identity seeded integer) field in the table and use that as the primary key.

Calsy
Back to Top
sanselmo View Drop Down
Newbie
Newbie
Avatar

Joined: 09-Nov-2007
Location: Canada
Posts: 7
Post Options Post Options   Quote sanselmo Quote  Post ReplyReply Direct Link To This Post Posted: 04-Feb-2009 at 11:01am
Hi,
 
I have problems working with 3 tables when doing the PersMng.SaveChanges() when I inserted a new instance of Table_1
 
Table_1
   pkNo_1
 
Table_2
   pkNo_2
 
Table_Link
   No_1  (key to Table_1)
   No_2  (key to Table_2)
   MoreInfoColumn
 
There is no primary key on Table_Link because its the 'combination' of the two column No_1 and No_2 (without having a single column of combination!)...
 
The error :
Save failed - Cannot persist entities that do not have a primary key: 'Model.Table_Link'
 
Is there a solution without adding a combined column that would also be a primary key?
 
seb
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down