Last active
August 29, 2015 14:07
-
-
Save bradymholt/85d348e9bdf2d1823e47 to your computer and use it in GitHub Desktop.
Entity Framework One-to-One Relationship
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataContext : DbContext | |
{ | |
public DbSet<Order> Orders { get; set; } | |
public DbSet<OrderDetail> OrderDetails { get; set; } | |
} | |
public class Order | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public virtual OrderDetail Detail { get; set; } | |
} | |
public class OrderDetail | |
{ | |
[Key] | |
[ForeignKey("Order")] //[ForeignKey] required for 1:1 | |
public int OrderId { get; set; } | |
public Order Order { get; set; } //Navigation property required for 1:1 | |
public string ReferenceNumber { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment