Allow to remove an index filter.
Add tests for the index filters Fluent API.
This commit is contained in:
Родитель
7920aa91a9
Коммит
a3dd89ae50
|
@ -295,7 +295,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations
|
|||
.Append(ColumnList(operation.Columns))
|
||||
.Append(")");
|
||||
|
||||
if (operation.Filter != null)
|
||||
if (!string.IsNullOrEmpty(operation.Filter))
|
||||
{
|
||||
builder
|
||||
.Append(" WHERE ")
|
||||
|
|
|
@ -37,10 +37,8 @@ namespace Microsoft.EntityFrameworkCore
|
|||
/// <param name="indexBuilder"> The builder for the index being configured. </param>
|
||||
/// <param name="sql"> The filter expression for the index. </param>
|
||||
/// <returns>A builder to further configure the index. </returns>
|
||||
public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [NotNull] string sql)
|
||||
public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string sql)
|
||||
{
|
||||
Check.NotEmpty(sql, nameof(sql));
|
||||
|
||||
indexBuilder.Metadata.Relational().Filter = sql;
|
||||
|
||||
return indexBuilder;
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Microsoft.EntityFrameworkCore.ModelBuilderTest
|
||||
{
|
||||
public static class RelationalTestModelBuilderExtensions
|
||||
{
|
||||
public static ModelBuilding.ModelBuilderTest.TestPropertyBuilder<TProperty> HasColumnName<TProperty>(
|
||||
this ModelBuilding.ModelBuilderTest.TestPropertyBuilder<TProperty> builder, string name)
|
||||
{
|
||||
var genericBuilder = (builder as IInfrastructure<PropertyBuilder<TProperty>>)?.Instance;
|
||||
|
||||
genericBuilder?.HasColumnName(name);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static ModelBuilding.ModelBuilderTest.TestReferenceOwnershipBuilder<TEntity, TRelatedEntity> ToTable<TEntity, TRelatedEntity>(
|
||||
this ModelBuilding.ModelBuilderTest.TestReferenceOwnershipBuilder<TEntity, TRelatedEntity> builder, string name)
|
||||
where TEntity : class
|
||||
where TRelatedEntity : class
|
||||
{
|
||||
var genericBuilder = (builder as IInfrastructure<ReferenceOwnershipBuilder<TEntity, TRelatedEntity>>)?.Instance;
|
||||
genericBuilder?.ToTable(name);
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Microsoft.EntityFrameworkCore.ModelBuilding
|
||||
{
|
||||
public static class RelationalTestModelBuilderExtensions
|
||||
{
|
||||
public static ModelBuilderTest.TestPropertyBuilder<TProperty> HasColumnName<TProperty>(
|
||||
this ModelBuilderTest.TestPropertyBuilder<TProperty> builder, string name)
|
||||
{
|
||||
var genericBuilder = (builder as IInfrastructure<PropertyBuilder<TProperty>>)?.Instance;
|
||||
if (genericBuilder != null)
|
||||
{
|
||||
genericBuilder.HasColumnName(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
(builder as IInfrastructure<PropertyBuilder>).Instance.HasColumnName(name);
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static ModelBuilderTest.TestReferenceOwnershipBuilder<TEntity, TRelatedEntity> ToTable<TEntity, TRelatedEntity>(
|
||||
this ModelBuilderTest.TestReferenceOwnershipBuilder<TEntity, TRelatedEntity> builder, string name)
|
||||
where TEntity : class
|
||||
where TRelatedEntity : class
|
||||
{
|
||||
var genericBuilder = (builder as IInfrastructure<ReferenceOwnershipBuilder<TEntity, TRelatedEntity>>)?.Instance;
|
||||
if (genericBuilder != null)
|
||||
{
|
||||
genericBuilder.ToTable(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
(builder as IInfrastructure<ReferenceOwnershipBuilder>).Instance.ToTable(name);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static ModelBuilderTest.TestIndexBuilder HasFilter(
|
||||
this ModelBuilderTest.TestIndexBuilder builder, string filterExpression)
|
||||
{
|
||||
var indexBuilder = builder.GetInfrastructure();
|
||||
indexBuilder.HasFilter(filterExpression);
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.ModelBuilderTest;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.EntityFrameworkCore.ModelBuilding
|
||||
|
@ -62,6 +61,14 @@ namespace Microsoft.EntityFrameworkCore.ModelBuilding
|
|||
entityTypeBuilder.Property(e => e.Name).HasColumnName(null);
|
||||
|
||||
Assert.Equal("[Name] IS NOT NULL", index.SqlServer().Filter);
|
||||
|
||||
indexBuilder.HasFilter("Foo");
|
||||
|
||||
Assert.Equal("Foo", index.SqlServer().Filter);
|
||||
|
||||
indexBuilder.HasFilter(null);
|
||||
|
||||
Assert.Null(index.SqlServer().Filter);
|
||||
}
|
||||
|
||||
protected override TestModelBuilder CreateModelBuilder()
|
||||
|
|
|
@ -168,7 +168,7 @@ namespace Microsoft.EntityFrameworkCore.ModelBuilding
|
|||
=> Wrap(EntityTypeBuilder.UsePropertyAccessMode(propertyAccessMode));
|
||||
}
|
||||
|
||||
protected class NonGenericTestPropertyBuilder<TProperty> : TestPropertyBuilder<TProperty>
|
||||
protected class NonGenericTestPropertyBuilder<TProperty> : TestPropertyBuilder<TProperty>, IInfrastructure<PropertyBuilder>
|
||||
{
|
||||
public NonGenericTestPropertyBuilder(PropertyBuilder propertyBuilder)
|
||||
{
|
||||
|
@ -223,6 +223,8 @@ namespace Microsoft.EntityFrameworkCore.ModelBuilding
|
|||
|
||||
public override TestPropertyBuilder<TProperty> UsePropertyAccessMode(PropertyAccessMode propertyAccessMode)
|
||||
=> new NonGenericTestPropertyBuilder<TProperty>(PropertyBuilder.UsePropertyAccessMode(propertyAccessMode));
|
||||
|
||||
PropertyBuilder IInfrastructure<PropertyBuilder>.Instance => PropertyBuilder;
|
||||
}
|
||||
|
||||
protected class NonGenericTestReferenceNavigationBuilder<TEntity, TRelatedEntity> : TestReferenceNavigationBuilder<TEntity, TRelatedEntity>
|
||||
|
@ -340,7 +342,7 @@ namespace Microsoft.EntityFrameworkCore.ModelBuilding
|
|||
}
|
||||
|
||||
protected class NonGenericTestReferenceOwnershipBuilder<TEntity, TRelatedEntity>
|
||||
: TestReferenceOwnershipBuilder<TEntity, TRelatedEntity>
|
||||
: TestReferenceOwnershipBuilder<TEntity, TRelatedEntity>, IInfrastructure<ReferenceOwnershipBuilder>
|
||||
where TEntity : class
|
||||
where TRelatedEntity : class
|
||||
{
|
||||
|
@ -439,6 +441,8 @@ namespace Microsoft.EntityFrameworkCore.ModelBuilding
|
|||
public override TestReferenceOwnershipBuilder<TEntity, TRelatedEntity> UsePropertyAccessMode(
|
||||
PropertyAccessMode propertyAccessMode)
|
||||
=> Wrap<TEntity, TRelatedEntity>(ReferenceOwnershipBuilder.UsePropertyAccessMode(propertyAccessMode));
|
||||
|
||||
ReferenceOwnershipBuilder IInfrastructure<ReferenceOwnershipBuilder>.Instance => ReferenceOwnershipBuilder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче