EF to one ratio

I'm having trouble saving a model with a small complex relationship to the database.

UML classes: enter image description here

Class Definition:

public abstract class EntityBase { public virtual Guid Id { get; set; } } public class LoanRequest : EntityBase { [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public virtual Applicant Applicant1 { get; set; } public virtual Applicant Applicant2 { get; set; } } public class Applicant { [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public Guid LoanRequestId { get; set; } [ForeignKey("LoanRequestId")] public virtual LoanRequest LoanRequest { get; set; } public virtual ICollection<MonthlyIncome> Incomes { get; set; } } public class MonthlyIncome { [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public Guid ApplicantId { get; set; } [ForeignKey("ApplicantId")] public virtual Applicant Applicant { get; set; } } 

I can start the migration and look at the database, the tables and columns created by the structure seem fine to me. But while saving the exception happens. The exception is:

It is not possible to determine the actual ordering for dependent operations. Dependencies may exist due to foreign key restrictions, model requirements, or store values.

I searched for a solution on the Internet and I don’t see where my problem is. Any suggestions? Thanks!

+5
source share
1 answer

After several attempts, I was able to find a solution. Change in the definition of the applicant to:

 public class Applicant { [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public virtual ICollection<MonthlyIncome> Incomes { get; set; } } 

All I need

+2
source

Source: https://habr.com/ru/post/1241515/


All Articles