Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Foreign key problem
Message
From
06/02/2010 03:36:22
 
 
To
06/02/2010 03:26:23
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
ASP.NET
Miscellaneous
Thread ID:
01447781
Message ID:
01447892
Views:
29
>>>>HI
>>>>
>>>>I've created a database in SQL2008. Two tables with a foreign key relationship.
>>>>
>>>>Then in Visual Studio2008 I'm trying to create a LINQ to SQL Data Model.
>>>>
>>>>I drag the tables onto the design surface but no Foreign key is appearing.
>>>>
>>>> I thought that appeared automatically if the key was defined in the database.
>>>>
>>>>Any ideas what I might have missed.
>>>>
>>>>
>>>>Thanks
>>>>
>>>>Nick
>>>
>>>Hmm I am not a EF person as of yet so take this with a grain of salt. I had heard the model hid the foreign key when there was a relationship set up as it takes care of that for you. Might want to do a search on that to see if I heard correctly.
>>>Tim
>>
>>Tim - I *think* you're thinking of the way EF will hide an intermediate linking table (when it contains only the keys). But I don't think it applies to L2Sql - and even it it did it wouldn't do so in this case where only two tables are involved.
>>
>>But Nick - can you clarify what you mean by "no foreign key is appearing".
>>Do you mean there's no association showing up in the diagram?
>>Can you, as Naomi suggested, post the code to create the DB?
>
>As an update If I add an entity model it does show the foreign key.
>
>Maybe the worked example in the book nerdinners is juts inaccurate and the dbml doesn't show foreign keys.l

Just this second created your DB in SQL2005 and used it to create a DBML.
The association shows up as expected ( one to many, Dinner.DinnerId -> RSVP.DinnerId)
Do you still get the problem is you delete the Linq to Sql files that were created and try again from scratch?
You can also try adding it yourself in the designer (right click / Add/ Association).....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform