Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mb.Entity<Question>()
- .HasMany(q => q.Variants)
- .WithOne()
- .HasForeignKey("QuestionId")
- .IsRequired()
- .OnDelete(DeleteBehavior.Cascade);
- mb.Entity<Question>()
- .HasOne(typeof(Variant))
- .WithOne()
- .HasForeignKey<Question>("AnsweredVariantId")
- .IsRequired(false)
- .OnDelete(DeleteBehavior.Restrict);
- // EF creates Unique Index for nullable fields
- mb.Entity<Question>()
- .HasIndex(q => q.AnsweredVariantId)
- .IsUnique(false);
- // create index instead of FK hence the cyclic dependency between Question and Variant
- mb.Entity<Question>()
- .HasIndex(q => q.CorrectVariantId)
- .IsUnique();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement