Advertisement
Veikedo

Untitled

Oct 17th, 2017
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1.             mb.Entity<Question>()
  2.                 .HasMany(q => q.Variants)
  3.                 .WithOne()
  4.                 .HasForeignKey("QuestionId")
  5.                 .IsRequired()
  6.                 .OnDelete(DeleteBehavior.Cascade);
  7.  
  8.             mb.Entity<Question>()
  9.                 .HasOne(typeof(Variant))
  10.                 .WithOne()
  11.                 .HasForeignKey<Question>("AnsweredVariantId")
  12.                 .IsRequired(false)
  13.                 .OnDelete(DeleteBehavior.Restrict);
  14.  
  15.             // EF creates Unique Index for nullable fields
  16.             mb.Entity<Question>()
  17.                 .HasIndex(q => q.AnsweredVariantId)
  18.                 .IsUnique(false);
  19.  
  20.             // create index instead of FK hence the cyclic dependency between Question and Variant
  21.             mb.Entity<Question>()
  22.                 .HasIndex(q => q.CorrectVariantId)
  23.                 .IsUnique();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement