Skip to content

Instantly share code, notes, and snippets.

@divega
Last active May 23, 2017 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divega/7cdf6b54310f2f142142c2a5e31186a0 to your computer and use it in GitHub Desktop.
Save divega/7cdf6b54310f2f142142c2a5e31186a0 to your computer and use it in GitHub Desktop.
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