I have those two entities,
public class PatientRegistry { [DatabaseGenerated (DatabaseGeneratedOption.Identity)] [Display (Name = "Record Id")] public long RecordId { get; set; } [Key, DatabaseGenerated (DatabaseGeneratedOption.None)] [Display (Name = "Patient File Number")] public long PatientFileId { get; set; } [Required, StringLength (50)] [Display (Name = "First Name")] public string FirstName { get; set; } public virtual ICollection<PartnerRegistry> Partners { get; set; } // public virtual ICollection<FileUpload> FileUpload { get; set; } public virtual PatientAccount PatientAccount { get; set; } }
and
public class PatientAccount { [Key, DatabaseGenerated (DatabaseGeneratedOption.Identity)] public long RecordId { get; set; } [Required, StringLength (15)] public string MobileNo { get; set; } public bool IsConfirmedPhoneNumber { get; set; } = false; public bool IsConfirmedEmailAddress { get; set; } = false; public bool IsLocked { get; set; } = false; public int? FailedAttempts { get; set; } public DateTimeOffset? LastLoggedIn { get; set; } public DateTimeOffset DateCreated { get; set; } [Timestamp] public byte[] RowVersion { get; set; } public long PatientFileId { get; set; } public virtual PatientRegistry PatientFile { get; set; } }
and I am defining the relationship using the fluent API,
builder.Entity<PatientRegistry> () .HasOne (a => a.PatientAccount) .WithOne (b => b.PatientFile) .HasForeignKey<PatientAccount> (c => c.PatientFileId) .OnDelete (DeleteBehavior.Cascade);
now I am trying to seed into the `PatientRegistry` table, I keep getting an error about null data in the PatientAccount table!!!!, why is this happening?