overview
Relationships define how two entities relate to each other.
public class Blog
{
public int Id { get; set; } // Primary Key
public string Name { get; set; }
public virtual Uri SiteUri { get; set; }
public ICollection<Post> Posts { get; }
}
public class Post
{
public string Title { get; set; }
public string Content { get; set; }
public DateTime PublishedOn { get; set; }
public Archived { get; set; }
public int BlogId { get; set; } // Foreign Key
public Blog Blog { get; set; }
}
Above:
- The
Blog.Posts
property connectsBlog
toPost.
- The
Post.Blog
property connectsPost
toBlog.
- This connection is said to be a one-to-one relationship.
- These properties are said to be navigations.
- Note that these two navigations result in one relationship.