6
votes

I have a 1:1 relationship between table 'A' and 'B' in my .DBML. The FK in the database is in place and the .DBML diagram shows an association line between 'A' and 'B'. However, I cannot get the code generator to create a child property in the 'A' entity. All I have is the FK column. In the Association properties, I have ChildProperty set to true. However, the code generator will not create the child property. I have dropped and added the two tables several times.

Anyone have any ideas?

2
I've had similar trouble when a table doesn't have a primary key or LINQ to SQL doesn't like the primary key on my table (for whatever reason). That might not be the problem here, but it's what comes to mind... - shaunmartin
@shaunmartin - that was the problem. Make this an answer to my question and I'll accept it as the answer. - Randy Minder

2 Answers

17
votes

The O/R designer will refuse to create an association property if a primary key is missing on one of the associated tables. Make sure all of your associated tables have a primary key.

0
votes

Not sure, but I think what you call 1:1 is actually seen by the DBML as 1:* because the list can "have" many of your fk-table, e.g. one empley oyee can have one city, but each city can "have" many employees.

AFAIK a primary key in each table is a prerequisite without which the DBML will not "work". An error is issued when saving it. Your project will compile, but you'll see the errors later. HTH