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

Table is generated for Keyless Entity Type, despite no model declaration #19972

Closed
JakenVeina opened this issue Feb 19, 2020 · 2 comments
Closed
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@JakenVeina
Copy link

JakenVeina commented Feb 19, 2020

Not sure if this issue is related to EF Core, or just Npgsql...

When defining a keyless entity type for use by raw SQL queries, the designer generates a ModelSnapshot that defines a table for this entity, despite the fact that I don't specify a table through ModelBuilder API, or through Attribute decorations. I don't see any obvious EntityTypeBuilder calls I can make to specify that no table should be generated, and I can't call .ToQuery() because the query that backs this entity needs to be raw. It includes a lot of function calls that EF doesn't translate.

Here is a minimal codebase that reproduces the issue, with the important bits shown below.

A sample entity definition...

public class MyTestKeylessEntity
{
    public MyTestKeylessEntity(
        long userId,
        int recordCount,
        long valueTotal)
    {
        UserId = userId;
        RecordCount = recordCount;
        ValueTotal = valueTotal;
    }

    public long UserId { get; }
    public int RecordCount { get; }
    public long ValueTotal { get; }
}

public class MyTestKeylessEntityConfigurator
    : IEntityTypeConfiguration<MyTestKeylessEntity>
{
    public void Configure(
            EntityTypeBuilder<MyTestKeylessEntity> entityTypeBuilder)
    {
        entityTypeBuilder
            .HasNoKey();
        entityTypeBuilder
            .Property(x => x.UserId);
        entityTypeBuilder
            .Property(x => x.RecordCount);
        entityTypeBuilder
            .Property(x => x.ValueTotal);
    }
}

The generated ModelSnapshot...

modelBuilder.Entity("EFCoreTest.MyTestKeylessEntity", b =>
    {
        b.Property<int>("RecordCount")
            .HasColumnType("integer");

        b.Property<long>("UserId")
            .HasColumnType("bigint");

        b.Property<long>("ValueTotal")
            .HasColumnType("bigint");

        b.ToTable("MyTestKeylessEntity");
    });

EF Core version: v3.1.1
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL v3.1.1.2
Target framework: .NET Core 3.1
Operating system: Windows 8.1 Pro x64
IDE: Visual Studio 2019 v16.4.5

@AdamDotNet
Copy link

Hi @JakenVeina. I was looking through this repository for the same reason as you, tables were being made for my Query types when I didn't want them to be.

#18116 has the workaround:

For now, you can just use something like .ToView("You forgot to use FromSql with ModQueueEntry")

But it is on the radar for EF Core 5.0:

Note from triage: closing this as duplicate since the work here is covered by #17270 and #2725.

Hope this helps!

@JakenVeina
Copy link
Author

Roger, thanks for the tip.

@ajcvickers ajcvickers added closed-no-further-action The issue is closed and no further action is planned. and removed type-bug labels Feb 21, 2020
JakenVeina added a commit to JakenVeina/MODiX that referenced this issue Feb 22, 2020
Scott-Caldwell pushed a commit to discord-csharp/MODiX that referenced this issue Feb 22, 2020
@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
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants