none
Object Relational Designer / Association code missing RRS feed

  • Question

  • Problem: Object Relational Designer / Association code missing

    Installed: Visual Studio 2008 Pro Version

    Just started using Linq to SQL (Lots of ADO.NET experience) and have run into a frustrating problem.

    I created a Linq to SQL class (using the wizard) and dropped six tables onto the designer surface.

    I then attempt to create Associations using the designer. These are not complex relationships, just “one-to-many” as I have done for years in different development environments.

    What happens is that the relationships are shown on the designer surface and the properties for each association appear correct but code is only being created for one of the associations and not the others. I have done quite a bit of research and can find no mention of this problem. I have deleted all file associated with the “dbml” and start over with the same results.

    All of the other entity code seems to be created and operate (tested) just fine.

    I was beginning to get pretty excited about Linq to SQL before I ran into this. Thanks for any help.

     

    Saturday, March 15, 2008 7:13 PM

Answers

  • I was having the same problem.  What I found was that for the associations that were working, the table that contained the Foreign Key, also had it's own Primary Key.  I tried adding a Primary Key to one of the tables where the association was failing, and after I regenerated it all, it worked as expected. 

    Seems like a bug in the code generation.  Does anyone else have any other suggestions / answers?
    Monday, March 17, 2008 9:05 PM

All replies

  • I was having the same problem.  What I found was that for the associations that were working, the table that contained the Foreign Key, also had it's own Primary Key.  I tried adding a Primary Key to one of the tables where the association was failing, and after I regenerated it all, it worked as expected. 

    Seems like a bug in the code generation.  Does anyone else have any other suggestions / answers?
    Monday, March 17, 2008 9:05 PM
  • Thanks Jeremy,

     

    Everything works now, I should have thought of it but I can find no limitation of this sort in the documentation – might be there, I just haven’t found it.

     

    Also I would like to know if it’s a bug or a design limit and why. I had to add primary keys to several tables that have no other use for them.

     

    Thanks again.

     

    Tuesday, March 18, 2008 12:06 AM
  • Friday, May 30, 2008 4:52 AM
  • It seems to have been a design decision.  See comments here.  Or if you can't log in there:

    "Hi,

    Thank you for your feedback. You are correct that associations are currently only supported if there is a primary key on both sides.

    We will review this and take it into consideration for a future version.

    Thanks,
    LINQ to SQL Team"

    Friday, May 30, 2008 3:30 PM