fork download
  1. using System;
  2.  
  3. //-----------------------------------------//
  4. public class Person
  5. {
  6. public int Id { get; set; }
  7. //
  8. public Relative Relative { get; set; }
  9. //
  10. public Other Other { get; set; }
  11. }
  12.  
  13. public class Other
  14. {
  15. public int Id { get; set; }
  16. //
  17. public int PersonId { get; set; }
  18. public Person Person { get; set; }
  19. }
  20.  
  21. public class Relative
  22. {
  23. public int Id { get; set; }
  24. //
  25. public int PersonId { get; set; }
  26. public Person Person { get; set; }
  27. }
  28.  
  29. //----- context --------------------------------------//
  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<Person>()
  39. .HasOne(p => p.Other)
  40. .WithOne(o => o.Person)
  41. .HasForeignKey<Other>(o => o.PersonId);
  42. mb.Entity<Person>()
  43. .HasOne(p => p.Relative)
  44. .WithOne(r => r.Person)
  45. .HasForeignKey<Relative>(r => r.PersonId);
  46. }
  47. }
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