Skip to content

Instantly share code, notes, and snippets.

@testfirstcoder
Created March 24, 2016 12:41
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 testfirstcoder/c93cc27d25e614b24f7e to your computer and use it in GitHub Desktop.
Save testfirstcoder/c93cc27d25e614b24f7e to your computer and use it in GitHub Desktop.
Entity Framework Fluent API - Unique key for multiple columns
public static class PropertyConfigurationExtensions
{
public static PrimitivePropertyConfiguration IsUnique(this PrimitivePropertyConfiguration configuration,
string indexName, int indexOrder)
{
var indexAttribute = new IndexAttribute(indexName, indexOrder)
{
IsUnique = true
};
return configuration.HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(indexAttribute));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment