Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Category
- {
- private ICollection<Post> posts;
- public Category()
- {
- this.posts = new HashSet<Post>();
- }
- public int CategoryId { get; set; }
- //virtual -> lazy loading Entity Framework
- public virtual ICollection<Post> Posts
- {
- get { return this.posts; }
- set { this.posts = value; }
- }
- }
- class Post
- {
- //primary key -> automatic set by Entity Framework id or class name + id
- public int PostId { get; set; }
- public string Title { get; set; }
- public string Content { get; set; }
- //foreign key -> automatic set by Entity Framework
- public int CategoryId { get; set; }
- //navigation property
- public virtual Category Category { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment