using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
public static void Main()
using (var context = new BookStore())
Category category1 = new Category()
CategoryName = "category 1",
Category category2= new Category()
CategoryName = "category 2",
context.Books.Add(book1);
context.Books.Add(book2);
context.Categories.Add(category1);
context.Categories.Add(category2);
var categories = context.Categories.ToList();
var books = context.Books.ToList();
FiddleHelper.WriteTable(books);
FiddleHelper.WriteTable(categories);
public class BookStore : DbContext
public BookStore() : base(FiddleHelper.GetConnectionStringSqlServer())
protected override void OnModelCreating(DbModelBuilder modelBuilder)
public DbSet<Category> Categories { get; set; }
public DbSet<Book> Books { get; set; }
public int BookId { get; set; }
public string Title { get; set; }
public int CatId { get; set; }
public string CategoryName { get; set; }