Skip to content

Instantly share code, notes, and snippets.

@akamud
Created November 9, 2014 12:34
Show Gist options
  • Save akamud/e815ed469b5b638e660d to your computer and use it in GitHub Desktop.
Save akamud/e815ed469b5b638e660d to your computer and use it in GitHub Desktop.
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public List<Post> Posts { get; set; }
}
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnConfiguring(DbContextOptions builder)
{
builder.UseSqlServer(@"Server=(localdb)\v11.0;Database=Blogging;Trusted_Connection=True;MultipleActiveResultSets=True;");
}
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Blog>()
.OneToMany(b => b.Posts, p => p.Blog)
.ForeignKey(p => p.BlogId);
}
}
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment