fork download
  1. using System;
  2.  
  3. public class Person
  4. {
  5. public int Id { get; set; }
  6. //
  7. public int RelativeId { get; set; }
  8. public Relative Relative { get; set; }
  9. //
  10. public int OtherId { get; set; }
  11. public Other Other { get; set; }
  12. }
  13.  
  14. public class Other
  15. {
  16. public int Id { get; set; }
  17. //
  18. public Person Person { get; set; }
  19. }
  20.  
  21. public class Relative
  22. {
  23. public int Id { get; set; }
  24. //
  25. public Person Person { get; set; }
  26. }
  27.  
  28. //============================================//
  29.  
  30. public class CemeteryContext : DbContext
  31. {
  32. public DbSet<Person> People { get; set; }
  33. public DbSet<Other> Others { get; set; }
  34. public DbSet<Relative> Relatives { get; set; }
  35.  
  36. protected override void OnModelCreating(ModelBuilder mb)
  37. {
  38. mb.Entity<Other>()
  39. .HasOne(o => o.Person)
  40. .WithOne(p => p.Other)
  41. .HasForeignKey<Person>(p => p.OtherId);
  42.  
  43. mb.Entity<Relative>()
  44. .HasOne(p => p.Person)
  45. .WithOne(r => r.Relative)
  46. .HasForeignKey<Person>(r => r.RelativeId);
  47. }
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(30,32): error CS0246: The type or namespace name `DbContext' could not be found. Are you missing an assembly reference?
prog.cs(32,12): error CS0246: The type or namespace name `DbSet' could not be found. Are you missing an assembly reference?
prog.cs(33,12): error CS0246: The type or namespace name `DbSet' could not be found. Are you missing an assembly reference?
prog.cs(34,12): error CS0246: The type or namespace name `DbSet' could not be found. Are you missing an assembly reference?
prog.cs(36,45): error CS0246: The type or namespace name `ModelBuilder' could not be found. Are you missing an assembly reference?
Compilation failed: 5 error(s), 0 warnings
stdout
Standard output is empty