Skip to content

Instantly share code, notes, and snippets.

Last active May 23, 2017
What would you like to do?
Pattern for configuring indexes in EF6.2
using System;
using System.Data.Entity;
namespace MyApplication
public class MyContext: DbContext
public DbSet<Person> People { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Entity<Person>().Property(p => p.Name).HasMaxLength(100);
modelBuilder.Entity<Person>().HasIndex(p => p.Name).IsUnique();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment