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

Default schema has no effect on views in EF Core 5.0 #23274

Closed
PawelGerr opened this issue Nov 11, 2020 · 1 comment · Fixed by #23278
Closed

Default schema has no effect on views in EF Core 5.0 #23274

PawelGerr opened this issue Nov 11, 2020 · 1 comment · Fixed by #23278
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression Servicing-approved type-bug
Milestone

Comments

@PawelGerr
Copy link

Default schema specified using modelBuilder.HasDefaultSchema('schema') has no effect on views defined using ToView('view name') in EF Core 5.0.

  • EF Core/DB Provider: Microsoft.EntityFrameworkCore.SqlServer 5.0.0
  • Target framework: .NET 5.0
  • OS: Win 10 x64
  • IDE: Jetbrains Rider

Actual behavior:
The query ctx.DemoView from the repro below generates: SELECT [d].[Id] FROM [DemoView] AS [d]

Expected behavior:
The query ctx.DemoView from the repro below generates: SELECT [d].[Id] FROM [demo].[DemoView] AS [d]

Repro

csproj file

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp5.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
    </ItemGroup>

</Project>

Program.cs

using System;
using Microsoft.EntityFrameworkCore;

namespace DefaultSchemaNotAppliedToViews
{
   class Program
   {
      static void Main(string[] args)
      {
         var options = new DbContextOptionsBuilder<DemoDbContext>()
            .UseSqlServer("server=localhost;database=demo;integrated security=true")
            .Options;

         using var ctx = new DemoDbContext(options);

         // SELECT [d].[Id] FROM [demo].[DemoEntities] AS [d]
         var text = ctx.DemoEntities.CreateDbCommand().CommandText;

         // actual: SELECT [d].[Id] FROM [DemoView] AS [d]
         // expected: SELECT [d].[Id] FROM [demo].[DemoView] AS [d]
         text = ctx.DemoView.CreateDbCommand().CommandText;
      }
   }

   public class DemoEntity
   {
      public Guid Id { get; set; }
   }

   public class DemoView
   {
      public Guid Id { get; set; }
   }

   public class DemoDbContext : DbContext
   {
      public DbSet<DemoEntity> DemoEntities { get; set; }
      public DbSet<DemoView> DemoView { get; set; }

      public DemoDbContext(DbContextOptions<DemoDbContext> options)
         : base(options)
      {
      }

      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
         base.OnModelCreating(modelBuilder);

         modelBuilder.Entity<DemoEntity>().ToTable("DemoEntities");
         modelBuilder.Entity<DemoView>().ToView("DemoView");

         modelBuilder.HasDefaultSchema("demo");
      }
   }
}
@ajcvickers
Copy link
Member

Conformed this a regression from 3.1.
/cc @AndriySvyryd

AndriySvyryd added a commit that referenced this issue Nov 12, 2020
AndriySvyryd added a commit that referenced this issue Nov 12, 2020
@AndriySvyryd AndriySvyryd added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. Servicing-consider and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels Nov 12, 2020
@ajcvickers ajcvickers added this to the 5.0.1 milestone Nov 12, 2020
AndriySvyryd added a commit that referenced this issue Nov 12, 2020
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 13, 2020
@AndriySvyryd AndriySvyryd removed their assignment Nov 13, 2020
shekky pushed a commit to shekky/Thinktecture.EntityFrameworkCore that referenced this issue Jan 17, 2021
shekky pushed a commit to shekky/Thinktecture.EntityFrameworkCore that referenced this issue Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression Servicing-approved type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants