using System; using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity.Infrastructure.Annotations; using System.Data.Entity.ModelConfiguration.Conventions; using System.Linq.Expressions; namespace IwbZero.EntityFramework { public class IndexingPropertyConvention : Convention where T : class { public IndexingPropertyConvention(Expression> propertyExpression, Func predicate = null) { predicate = predicate ?? (t => true); Types() .Where(t => predicate(t)) .Configure(e => e.Property(propertyExpression).HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute { IsClustered = false, IsUnique = false }))); } } }