Describe your issue
Hello. There is a problem related to composite primary keys. When we are using scaffolding via the CLI, attribute generation for associations is incorrect. Duplicated key values appears in the attribute. the LoadWith<> method does not work because of that .
Steps to reproduce
-
Create DB with 2 tables:
- First table with name PKTable and colums Id, AnotherId
- Second table with name FKTable and colums PKTableId, PKTableAnotherId
-
Create Composite PK for PKTable with columns Id and AnotherId
-
Create Composite FK for FKTable with columns PKTableId and PKTableAnotherId to PKTable to Id and AnotherId
-
Run CLI command dotnet linq2db scaffold -i database.json
-
Fill DB some random data
-
Write any query with LoadWith<> Method
-
Get null on association property
[Table("PKTable")]
public class PkTable
{
[Column("Id" , IsPrimaryKey = true, PrimaryKeyOrder = 0, IsIdentity = true, SkipOnInsert = true, SkipOnUpdate = true)] public int Id { get; set; } // integer
[Column("AnotherId", IsPrimaryKey = true, PrimaryKeyOrder = 1 )] public int AnotherId { get; set; } // integer
#region Associations
/// <summary>
/// FKTable_PKTableAnotherId_PKTableId _fkey backreference
/// </summary>
[Association(ThisKey = nameof(Id) + "," + nameof(Id), OtherKey = nameof(FkTable.PkTableId) + "," + nameof(Id))]
public List<FkTable> FkTablePkTableAnotherIdPkTableIdFkeys { get; set; } = null!;
#endregion
}
[Table("FKTable")]
public class FkTable
{
[Column("Id" , IsPrimaryKey = true, IsIdentity = true, SkipOnInsert = true, SkipOnUpdate = true)] public int Id { get; set; } // integer
[Column("PKTableId " )] public int? PkTableId { get; set; } // integer
[Column("PKTableAnotherId" )] public int? PkTableAnotherId { get; set; } // integer
#region Associations
/// <summary>
/// FKTable_PKTableAnotherId_PKTableId _fkey
/// </summary>
[Association(ThisKey = nameof(PkTableId) + "," + nameof(PkTableId), OtherKey = nameof(PkTable.Id) + "," + nameof(PkTableId))]
public PkTable? PkTableAnotherIdPkTableIdFkey { get; set; }
#endregion
}
Environment details
Linq To DB version: 4.3.0
Database (with version): PostgreSQL 14
ADO.NET Provider (with version): NpgSql 7.0.0-rc.1
Operating system: Windows 10
.NET Version: 7.0
Solution suggestion


Describe your issue
Hello. There is a problem related to composite primary keys. When we are using scaffolding via the CLI, attribute generation for associations is incorrect. Duplicated key values appears in the attribute. the LoadWith<> method does not work because of that .
Steps to reproduce
Create DB with 2 tables:
Create Composite PK for PKTable with columns Id and AnotherId
Create Composite FK for FKTable with columns PKTableId and PKTableAnotherId to PKTable to Id and AnotherId
Run CLI command dotnet linq2db scaffold -i database.json
Fill DB some random data
Write any query with LoadWith<> Method
Get null on association property
Environment details
Linq To DBversion: 4.3.0Database (with version): PostgreSQL 14
ADO.NET Provider (with version): NpgSql 7.0.0-rc.1
Operating system: Windows 10
.NET Version: 7.0
Solution suggestion