Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0.1] Migrations: Skip DbFunctionAttributeConvention when creating model for history repository #23452

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/EFCore.Relational/Migrations/HistoryRepository.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -98,6 +99,11 @@ private IModel EnsureModel()

// Use public API to remove the convention, issue #214
ConventionSet.Remove(conventionSet.ModelInitializedConventions, typeof(DbSetFindingConvention));
if (!(AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue23312", out var enabled) && enabled))
{
ConventionSet.Remove(conventionSet.ModelInitializedConventions, typeof(RelationalDbFunctionAttributeConvention));
}

var modelBuilder = new ModelBuilder(conventionSet);
modelBuilder.Entity<HistoryRow>(
x =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.TestUtilities;
Expand Down Expand Up @@ -157,13 +158,44 @@ public void GetEndIfScript_works()
}

private static IHistoryRepository CreateHistoryRepository(string schema = null)
=> new DbContext(
=> new TestDbContext(
new DbContextOptionsBuilder()
.UseInternalServiceProvider(SqlServerTestHelpers.Instance.CreateServiceProvider())
.UseSqlServer(
new SqlConnection("Database=DummyDatabase"),
b => b.MigrationsHistoryTable(HistoryRepository.DefaultTableName, schema))
.Options)
.GetService<IHistoryRepository>();

private class TestDbContext : DbContext
{
public TestDbContext(DbContextOptions options)
: base(options)
{
}

public DbSet<Blog> Blogs { get; set; }

[DbFunction("TableFunction")]
public IQueryable<TableFunction> TableFunction()
=> FromExpression(() => TableFunction());

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}

}

private class Blog
{
public int Id { get; set; }
}

private class TableFunction
{
public int Id { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
}
}