New Posts New Posts RSS Feed: Add/Insert & one to one mappings (SL)
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Add/Insert & one to one mappings (SL)

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

Joined: 29-Jul-2010
Location: ZA
Posts: 28
Post Options Post Options   Quote pompomJuice Quote  Post ReplyReply Direct Link To This Post Topic: Add/Insert & one to one mappings (SL)
    Posted: 10-Dec-2010 at 1:54am

Hi.

I am trying to achieve a one to one mapping in my data. Firstly I set up this relationship in the database by setting one table's primary key as a foreign key into another table.
 
Entity1.PK  <-------- Entity2.PK/FK
 
Ideablade imports the model and everything seems to work until you try to do an insert Entity1/Entity2 pair in one transaction. An exception is thrown: A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column:Entity1.PK"
 
A Entity1/Entity2 pair insert within one transaction works fine if you relate them in a one to many fashion though:
 
                               Entity2.PK
Entity1.PK <--------- Entity2.FK
 
... where I presume EntityManger or EF 4.0 first insterts Entity1, extracts its generated PK and use that when inserting Entity2. I'm guessing.
 
I am assuming this does not work with one to one relationships? Do I have to manually commit entity1, extract its PK so that I can use it to insert Entity2. This makes reject changes more compicated etc etc. What do I do here?
 
Back to Top
pompomJuice View Drop Down
Newbie
Newbie
Avatar

Joined: 29-Jul-2010
Location: ZA
Posts: 28
Post Options Post Options   Quote pompomJuice Quote  Post ReplyReply Direct Link To This Post Posted: 10-Dec-2010 at 5:53am
Aah, never mind.
 
I found the problem.
 
If you create the FK relationship Entity1.PK <------- Entity2.PK/FK then you must drag the mouse from entity1.PK to entity2.PK/FK when you are in SSMS's Database Diagram Mode. Basically my foreign key was the wrong way around and I failed to spot it.
 
Usually when you make FKs you drag the FK from the Foreign Key Base Table to the Primary/Unique Key Base table's PK. But when your FK is a PK, you have to drag it the other way around for some reason. Bizarre.


Edited by pompomJuice - 10-Dec-2010 at 5:57am
Back to Top
olegasd View Drop Down
Newbie
Newbie


Joined: 31-Aug-2012
Posts: 1
Post Options Post Options   Quote olegasd Quote  Post ReplyReply Direct Link To This Post Posted: 31-Aug-2012 at 8:05am
Originally posted by pompomJuice

Aah, never mind.
 
I found the problem.
 
If you create the FK relationship Entity1.PK <------- Entity2.PK/FK then you must drag the mouse from entity1.PK to entity2.PK/FK when you are in SSMS's Database Diagram Mode. Basically my foreign key was the wrong way around and I failed to spot it.
 
Usually when you make FKs you drag the FK from the Foreign Key Base Table to the Primary/Unique Key Base table's PK. But when your FK is a PK, you have to drag it the other way around for some reason. Bizarre.


Thanks a lot! It was helpful for me, my problem solved. Thanks!

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down