using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.Infrastructure.Annotations;
public static void Main()
using (var context = new BookStore())
FiddleHelper.WriteTable(context.Authors.ToList());
public static void InsertData()
using (var context = new BookStore())
var Authors = new List<Author>
new Author() {FirstName = "Mark", LastName = "Cuban", Email = "mark.cuban@example.com"},
new Author() {FirstName = "Andy", LastName = "Holloway", Email = "andy.holloway@example.com"}
context.Authors.AddRange(Authors);
public class BookStore : DbContext
public BookStore() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Author> Authors { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Entity<Author>()
.HasColumnType("VARCHAR")
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("Index_Email") { IsUnique = true }));
public int AuthorId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }