Skip to content

Instantly share code, notes, and snippets.

@jahands
Created February 26, 2015 05:14
Show Gist options
  • Save jahands/72c19c12f2b490cdc837 to your computer and use it in GitHub Desktop.
Save jahands/72c19c12f2b490cdc837 to your computer and use it in GitHub Desktop.
EF Code-first IsUnique()
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Infrastructure.Annotations;
using System.Data.Entity.ModelConfiguration.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Imflow.Data
{
public static class MappingExtensions
{
public static PrimitivePropertyConfiguration IsUnique(this PrimitivePropertyConfiguration configuration)
{
return configuration.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute { IsUnique = true }));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment