public class PiCollectiveIdentity { public Guid Id { get; set; } = new Guid(); public long IdentityId { get; set; } public required string Name { get; set; } [ForeignKey("IdentityName")] public IList<PiCollectiveIdentityMapping> Mappings { get; set; } = new List<PiCollectiveIdentityMapping>(); } public class PiCollectiveIdentityMapping{ public Guid Id { get; set; } = new Guid(); public DateTime CollectionDate { get; set; } = DateTime.UtcNow; public required string IdentityName { get; set; } public PiCollectiveIdentity ? Identity { get; set; } = null; }
public class PiCollectiveIdentity { public Guid Id { get; set; } = new Guid(); public long IdentityId { get; set; } public required string Name { get; set; } [ForeignKey("IdentityName")] public IList<PiCollectiveIdentityMapping> Mappings { get; set; } = new List<PiCollectiveIdentityMapping>(); } public class PiCollectiveIdentityMapping{ public Guid Id { get; set; } = new Guid(); public DateTime CollectionDate { get; set; } = DateTime.UtcNow; public required string IdentityName { get; set; } public PiCollectiveIdentity ? Identity { get; set; } = null; }
Where each database record will have it's own unique ID, but the relationship between the two records is based on name (due to pulling the data from a 3rd party system). However, this throws an error when attempting to migrate for
'PiCollectiveIdentityMapping.Mappings' with foreign key properties {'IdentityName' : string} cannot target the primary key {'Id' : Guid} because it is not compatible
'PiCollectiveIdentityMapping.Mappings' with foreign key properties {'IdentityName' : string} cannot target the primary key {'Id' : Guid} because it is not compatible