Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq-To-SQL Association with Multiple Foreign Keys Problem
    text
    copied!<p>I'm using Visual Studio 2008, C#, LINQ to SQL, and using the datbase dbml GUI editor to create a database. I want to create a 1 to many relationship, but in my case the 1 object has 2 primary keys. Using the GUI edtior I created the association, but when the program runs and the database is created, I get the error: </p> <p><strong>"The referenced table must have a primary or candidate key. [ FK Name = Screen_Pixel ]"</strong></p> <p>The XML created in the dbml looks like:</p> <pre><code>&lt;Table Name="Screen"&gt; &lt;Column Name="PKA1" Type="System.Int64" IsPrimaryKey="true" CanBeNull="false" UpdateCheck="Never" /&gt; &lt;Column Name="PKA2" Type="System.Int32" IsPrimaryKey="true" CanBeNull="false" UpdateCheck="Never" /&gt; &lt;Association Name="Screen_Pixel" Member="Pixels" ThisKey="PKA1,PKA2" OtherKey="PKB1,PKB2" Type="Pixel" /&gt; &lt;/Table&gt; &lt;Table Name="Pixel&gt; &lt;Column Name="PKB1" Type="System.Int64" IsPrimaryKey="true" CanBeNull="false" UpdateCheck="Never" /&gt; &lt;Column Name="PKB2" Type="System.Int32" IsPrimaryKey="true" CanBeNull="false" UpdateCheck="Never" /&gt; &lt;Column Name="PKB3" Type="System.Int32" IsPrimaryKey="true" CanBeNull="false" UpdateCheck="Never" /&gt; &lt;Association Name="Screen_Pixel" Member="Screen" ThisKey="PKB1,PKB2" OtherKey="PKA1,PKA2" Type="Screen" IsForeignKey="true" /&gt; &lt;/Table&gt; </code></pre> <p>The generated associations in C# code are:</p> <pre><code>[Association(Name=@"Screen_Pixel", Storage=@"_Screen", ThisKey=@"PKA1,PKA2", OtherKey=@"PKB1,PKB2", IsForeignKey=true)] [Association(Name=@"Screen_Pixel", Storage=@"_Pixels", ThisKey=@"PKB1,PKB2", OtherKey=@"PKA1,PKA2")] </code></pre> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload