diff --git a/src/EFCore.Relational/Migrations/HistoryRepository.cs b/src/EFCore.Relational/Migrations/HistoryRepository.cs index e5147b40801..40b078e7db1 100644 --- a/src/EFCore.Relational/Migrations/HistoryRepository.cs +++ b/src/EFCore.Relational/Migrations/HistoryRepository.cs @@ -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; @@ -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( x => diff --git a/test/EFCore.SqlServer.Tests/Migrations/SqlServerHistoryRepositoryTest.cs b/test/EFCore.SqlServer.Tests/Migrations/SqlServerHistoryRepositoryTest.cs index 574d83be2e4..f2ebec98e8a 100644 --- a/test/EFCore.SqlServer.Tests/Migrations/SqlServerHistoryRepositoryTest.cs +++ b/test/EFCore.SqlServer.Tests/Migrations/SqlServerHistoryRepositoryTest.cs @@ -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; @@ -157,7 +158,7 @@ public void GetEndIfScript_works() } private static IHistoryRepository CreateHistoryRepository(string schema = null) - => new DbContext( + => new TestDbContext( new DbContextOptionsBuilder() .UseInternalServiceProvider(SqlServerTestHelpers.Instance.CreateServiceProvider()) .UseSqlServer( @@ -165,5 +166,36 @@ private static IHistoryRepository CreateHistoryRepository(string schema = null) b => b.MigrationsHistoryTable(HistoryRepository.DefaultTableName, schema)) .Options) .GetService(); + + private class TestDbContext : DbContext + { + public TestDbContext(DbContextOptions options) + : base(options) + { + } + + public DbSet Blogs { get; set; } + + [DbFunction("TableFunction")] + public IQueryable 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; } + } } }