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())
Author createdBy = new Author()
Author updatedBy = new Author()
var authorData = context.Authors.ToList();
FiddleHelper.WriteTable(authorData);
var books = context.Books.ToList();
FiddleHelper.WriteTable(books);
public class BookStore : DbContext
public BookStore() : base(FiddleHelper.GetConnectionStringSqlServer())
protected override void OnModelCreating(DbModelBuilder modelBuilder)
public DbSet<Author> Authors { get; set; }
public DbSet<Book> Books { get; set; }
public int BookId { get; set; }
public string Title { get; set; }
public Author CreatedBy { get; set; }
public Author UpdatedBy { get; set; }
public int AuthorId { get; set; }
public string Name { get; set; }
[InverseProperty("CreatedBy")]
public virtual ICollection<Book> BooksWritten { get; set; }
[InverseProperty("UpdatedBy")]
public virtual ICollection<Book> BooksUpdated { get; set; }