Skip to content

Instantly share code, notes, and snippets.

@ngohungphuc
Created August 2, 2019 08:54
Show Gist options
  • Save ngohungphuc/2651d80f38ea5d24663195ed43bcd163 to your computer and use it in GitHub Desktop.
Save ngohungphuc/2651d80f38ea5d24663195ed43bcd163 to your computer and use it in GitHub Desktop.
public class Post
{
public int UserId { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }
public string Title { get; set; }
public string Body { get; set; }
public ICollection<Comment> Comments { get; set; }
}
public class Comment
{
[ForeignKey("PostId")]
public Post Post { get; set; }
public int PostId { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Body { get; set; }
}
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options)
{
}
public DbSet<Comment> Comments { get; set; }
public DbSet<Post> Posts { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment