I am working with c#, .net5, and I have successfully included two new Entities (tables TableA and TableB) to my already working solution. The solution run smoothly, even though adding new entries to the new two tables runs without problem.
The issue comes when I try to run a very simple new Testing class (IClassFixture). when I run a basic method test, I have this following error,
System.AggregateException : The relationship from
'EntityB.FK'to'EntityA'with foreign key properties{'MTime' : DateTime, 'MId' : long}cannot target the primary key{'Id' : long}because it is not compatible. Configure a principal key or a set of compatible foreign key properties for this relationship.
so I don't understand why and how such an error comes here (even though the system is running without any issue) ? is there any solution to bypass this ?
public class EntityA
{
[Key]
[Column("id")]
public long Id { get; set; }
[Column("time")]
[Required]
public DateTime Time { get; set; }
[Column("value")]
[Required]
public float Value { get; set; }
}
public class EntityB
{
[Key]
[Column("id")]
public long Id { get; set; }
[Column("value", TypeName = "jsonb")]
[Required]
public string Value { get; set; }
[Column("m_id")]
[Required]
public long MId { get; set; }
[Column("m_time")]
public DateTime MTime { get; set; }
[ForeignKey("MTime, MId")]
public virtual EntityA FK{ get; set; }
}
Note that the EntityA has two primary keys and are added successfully to the database.
modelBuilder.Entity<EntityA>().HasKey(m =>
new { m.Time, m.Id });