Visual Studio 2008、C#、LINQ to SQL を使用し、データベースを作成するためにデータベース dbml GUI エディターを使用しています。1 対多の関係を作成したいのですが、私の場合、1 つのオブジェクトに 2 つの主キーがあります。GUI edtior を使用して関連付けを作成しましたが、プログラムを実行してデータベースを作成すると、次のエラーが表示されます。
「参照されるテーブルには主キーまたは候補キーが必要です。[ FK 名 = Screen_Pixel ]」
dbml で作成された XML は次のようになります。
<Table Name="Screen">
<Column Name="PKA1" Type="System.Int64" IsPrimaryKey="true" CanBeNull="false" UpdateCheck="Never" />
<Column Name="PKA2" Type="System.Int32" IsPrimaryKey="true" CanBeNull="false" UpdateCheck="Never" />
<Association Name="Screen_Pixel" Member="Pixels" ThisKey="PKA1,PKA2" OtherKey="PKB1,PKB2" Type="Pixel" />
</Table>
<Table Name="Pixel>
<Column Name="PKB1" Type="System.Int64" IsPrimaryKey="true" CanBeNull="false" UpdateCheck="Never" />
<Column Name="PKB2" Type="System.Int32" IsPrimaryKey="true" CanBeNull="false" UpdateCheck="Never" />
<Column Name="PKB3" Type="System.Int32" IsPrimaryKey="true" CanBeNull="false" UpdateCheck="Never" />
<Association Name="Screen_Pixel" Member="Screen" ThisKey="PKB1,PKB2" OtherKey="PKA1,PKA2" Type="Screen" IsForeignKey="true" />
</Table>
C# コードで生成される関連付けは次のとおりです。
[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")]
何か案は?