Keyless Entity Types - EF Core still checks primary keys

.net-core c# entity-framework-core

Question

I've got access to view "vm_EmpNr" in database and I'am trying to reach it by keyless entity type

public DbSet<User> Users { get; set; }

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

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>(options =>
            {
                options.HasNoKey();
                options.ToView("v_EmpNr");
            });
        }

but despite of using "HasNoKey" in entity options I am receiving error: "The invoked method is cannot be used for the entity type 'User' because it does not have a primary key.".

My poject dependencies:

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.0" />
  </ItemGroup>

This is my first situation with keyless entity types and I don't know if maybe I miss something

1
0
11/25/2019 11:44:21 AM

Accepted Answer

Update Entity Framework to 3.0.1v solves a problem

1
11/25/2019 12:18:19 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow