private static void BuildIndex( AttributedIndexBuilderOptions options, EntityTypeBuilder builder1, OwnedNavigationBuilder builder2, IndexBuilderArgument builderArg, Action <IndexBuilder, IndexBuilderArgument> postProcess) { if (!options.SuppressNotSupportedException.IsClustered && builderArg.IsClustered) { throw new NotSupportedException( "\"IsClustered=true\" of [Index] attribute is not supported.\n" + "If you want to use \"IsClustered=true\", you need to call \"BuildIndexesFromAnnotationsForSqlServer()\" (in the Toolbelt.EntityFrameworkCore.IndexAttribute.SqlServer package) instead of \"BuildIndexesFromAnnotations()\", for a SQL Server connection.\n" + "You can also suppress this exception by calling like \"BuildIndexesFromAnnotations(options => options.SupressUnsupportedException.IsClustered = true)\""); } if (!options.SuppressNotSupportedException.Includes && (builderArg.Includes ?? new string[0]).Any()) { throw new NotSupportedException( "\"Includes\" of [Index] attribute is not supported.\n" + "If you want to use \"Includes\", you need to call \"BuildIndexesFromAnnotationsForSqlServer()\" (in the Toolbelt.EntityFrameworkCore.IndexAttribute.SqlServer package) instead of \"BuildIndexesFromAnnotations()\", for a SQL Server connection.\n" + "You can also suppress this exception by calling like \"BuildIndexesFromAnnotations(options => options.SupressUnsupportedException.Includes = true)\""); } var indexBuilder = builder1?.HasIndex(builderArg.PropertyNames) ?? builder2.HasIndex(builderArg.PropertyNames); indexBuilder.IsUnique(builderArg.IsUnique); if (builderArg.IndexName != "") { indexBuilder.HasName(builderArg.IndexName); } postProcess?.Invoke(indexBuilder, builderArg); }
internal static void BuildIndexesFromAnnotations( this ModelBuilder modelBuilder, Action <IndexBuilder, IndexBuilderArgument> postProcessForIndex, Action <KeyBuilder, IndexBuilderArgument> postProcessForPrimaryKey, Action <AttributedIndexBuilderOptions> configure ) { var options = new AttributedIndexBuilderOptions(); configure?.Invoke(options); AnnotationBasedModelBuilder.Build <IndexAttribute, IndexBuilderArgument>( modelBuilder, (props) => CreateBuilderArguments(props, (attr, propNames) => new IndexBuilderArgument(attr, propNames)), (b1, b2, arg) => BuildIndex(options, b1, b2, arg, postProcessForIndex)); AnnotationBasedModelBuilder.Build <PrimaryKeyAttribute, IndexBuilderArgument>( modelBuilder, (props) => CreateBuilderArguments(props, (attr, propNames) => new IndexBuilderArgument(attr, propNames)), (b1, b2, arg) => BuildPrimaryKey(b1, b2, arg, postProcessForPrimaryKey)); }