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

Migrations: keyless type without table/view created in ModelSnapshot #25183

Closed
JonaBrackenwood opened this issue Jul 1, 2021 · 2 comments
Closed

Comments

@JonaBrackenwood
Copy link

I have e a keyless entity type that is used as the return type of a raw query. Entity and context are defined as followed:

    public class Context : DbContext
    {
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<QueryResult>().HasNoKey().ToView(null).ToTable(null);
        }
    }

    public class QueryResult
    {
        public string Result { get; set; }
    }

Creating a first migration on this context works as expected and creates an empty migration file.
When creating a second migration, the following migration file is created:

    public partial class Test2 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "QueryResult");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "QueryResult",
                columns: table => new
                {
                    Result = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                });
        }
    }

When updating the database, this throws an error as the table doesn't and indeed shouldn't exist.
When inspecting the ContextModelSnapshot, QueryResult is present, which shouldn't be the case.

Using EF Core 5.0.7 on .NET 5.0.

@bricelam
Copy link
Contributor

bricelam commented Jul 2, 2021

Duplicate of #25133?

@JonaBrackenwood
Copy link
Author

Duplicate of #25133?

Ah, indeed, didn't see that one. Thanks!

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants