A
Adrian
I have a test DBML file:-
<?xml version="1.0" encoding="utf-8"?>
<Database Name="myDB" EntityNamespace="MyEntNS" ContextNamespace="MyConNs" Class="DBdc" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
<Table Name="dbo.PARENTTABLE" Member="PARENTTABLE">
<Type Name="PARENTTABLE">
<Column Name="keycol1" Member="keycol1" Type="System.Decimal" DbType="Decimal(10,0) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="keycol2" Member="keycol2" Type="System.Decimal" DbType="Decimal(10,0) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="keycol3" Member="keycol3" Type="System.String" DbType="VarChar(10) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Association Name="fk_1064" Member="fkCHILDTABLE" ThisKey="keycol3,keycol1,keycol2" OtherKey="fkeycol3,fkeycol1,fkeycol2" Type="CHILDTABLE" DeleteRule="NO ACTION" />
</Type>
</Table>
<Table Name="dbo.CHILDTABLE" Member="CHILDTABLE">
<Type Name="CHILDTABLE">
<Column Name="main_id" Member="publish_id" Type="System.String" DbType="VarChar(10) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="fkeycol1" Member="fkeycol1" Type="System.Decimal" DbType="Decimal(10,0)" CanBeNull="true" />
<Column Name="fkeycol2" Member="fkeycol2" Type="System.Decimal" DbType="Decimal(10,0)" CanBeNull="true" />
<Column Name="fkeycol3" Member="fkeycol3" Type="System.String" DbType="VarChar(10)" CanBeNull="true" />
<Association Name="fk_1064" Member="pkPARENTTABLE" ThisKey="fkeycol3,fkeycol1,fkeycol2" OtherKey="keycol3,keycol1,keycol2" Type="PARENTTABLE" IsForeignKey="true" />
</Type>
</Table>
</Database>
Note that the order of the columns on the PARENTTABLE are listed correctly as keycol1, keycol2, keycol3, but the promary key on the table is actually keycol3, keycol1, keycol2. The association elements do use the correct primary key sequences. However, when I generate the VB for this DBML, it gets it wrong.. see the text below highlighted in red.
<Association(Name:="fk_1064", Storage:="_pkPARENTTABLE", ThisKey:="fkeycol3,fkeycol1,fkeycol2", IsForeignKey:=true)> _
Public Property pkPARENTTABLE() As PARENTTABLE
Get
Return Me._pkPARENTTABLE.Entity
End Get
Set
Dim previousValue As PARENTTABLE = Me._pkPARENTTABLE.Entity
If ((Object.Equals(previousValue, value) = false) _
OrElse (Me._pkPARENTTABLE.HasLoadedOrAssignedValue = false)) Then
Me.SendPropertyChanging
If ((previousValue Is Nothing) _
= false) Then
Me._pkPARENTTABLE.Entity = Nothing
previousValue.fkCHILDTABLE.Remove(Me)
End If
Me._pkPARENTTABLE.Entity = value
If ((value Is Nothing) _
= false) Then
value.fkCHILDTABLE.Add(Me)
Me._fkeycol3 = value.keycol1
Me._fkeycol1 = value.keycol2
Me._fkeycol2 = value.keycol3
Else
Me._fkeycol3 = CType(Nothing, String)
Me._fkeycol1 = CType(Nothing, Nullable(Of Decimal))
Me._fkeycol2 = CType(Nothing, Nullable(Of Decimal))
End If
Me.SendPropertyChanged("pkPARENTTABLE")
End If
End Set
End Property
Is there something wrong with the DBML or is it a bug in SQLMetal ?
(this is using the RTM (1.00.21022) version of SQLMetal)
<?xml version="1.0" encoding="utf-8"?>
<Database Name="myDB" EntityNamespace="MyEntNS" ContextNamespace="MyConNs" Class="DBdc" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
<Table Name="dbo.PARENTTABLE" Member="PARENTTABLE">
<Type Name="PARENTTABLE">
<Column Name="keycol1" Member="keycol1" Type="System.Decimal" DbType="Decimal(10,0) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="keycol2" Member="keycol2" Type="System.Decimal" DbType="Decimal(10,0) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="keycol3" Member="keycol3" Type="System.String" DbType="VarChar(10) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Association Name="fk_1064" Member="fkCHILDTABLE" ThisKey="keycol3,keycol1,keycol2" OtherKey="fkeycol3,fkeycol1,fkeycol2" Type="CHILDTABLE" DeleteRule="NO ACTION" />
</Type>
</Table>
<Table Name="dbo.CHILDTABLE" Member="CHILDTABLE">
<Type Name="CHILDTABLE">
<Column Name="main_id" Member="publish_id" Type="System.String" DbType="VarChar(10) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="fkeycol1" Member="fkeycol1" Type="System.Decimal" DbType="Decimal(10,0)" CanBeNull="true" />
<Column Name="fkeycol2" Member="fkeycol2" Type="System.Decimal" DbType="Decimal(10,0)" CanBeNull="true" />
<Column Name="fkeycol3" Member="fkeycol3" Type="System.String" DbType="VarChar(10)" CanBeNull="true" />
<Association Name="fk_1064" Member="pkPARENTTABLE" ThisKey="fkeycol3,fkeycol1,fkeycol2" OtherKey="keycol3,keycol1,keycol2" Type="PARENTTABLE" IsForeignKey="true" />
</Type>
</Table>
</Database>
Note that the order of the columns on the PARENTTABLE are listed correctly as keycol1, keycol2, keycol3, but the promary key on the table is actually keycol3, keycol1, keycol2. The association elements do use the correct primary key sequences. However, when I generate the VB for this DBML, it gets it wrong.. see the text below highlighted in red.
<Association(Name:="fk_1064", Storage:="_pkPARENTTABLE", ThisKey:="fkeycol3,fkeycol1,fkeycol2", IsForeignKey:=true)> _
Public Property pkPARENTTABLE() As PARENTTABLE
Get
Return Me._pkPARENTTABLE.Entity
End Get
Set
Dim previousValue As PARENTTABLE = Me._pkPARENTTABLE.Entity
If ((Object.Equals(previousValue, value) = false) _
OrElse (Me._pkPARENTTABLE.HasLoadedOrAssignedValue = false)) Then
Me.SendPropertyChanging
If ((previousValue Is Nothing) _
= false) Then
Me._pkPARENTTABLE.Entity = Nothing
previousValue.fkCHILDTABLE.Remove(Me)
End If
Me._pkPARENTTABLE.Entity = value
If ((value Is Nothing) _
= false) Then
value.fkCHILDTABLE.Add(Me)
Me._fkeycol3 = value.keycol1
Me._fkeycol1 = value.keycol2
Me._fkeycol2 = value.keycol3
Else
Me._fkeycol3 = CType(Nothing, String)
Me._fkeycol1 = CType(Nothing, Nullable(Of Decimal))
Me._fkeycol2 = CType(Nothing, Nullable(Of Decimal))
End If
Me.SendPropertyChanged("pkPARENTTABLE")
End If
End Set
End Property
Is there something wrong with the DBML or is it a bug in SQLMetal ?
(this is using the RTM (1.00.21022) version of SQLMetal)