Last active
May 23, 2017 00:21
-
-
Save divega/7cdf6b54310f2f142142c2a5e31186a0 to your computer and use it in GitHub Desktop.
Pattern for configuring indexes in EF6.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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