Julia
Julia

Reputation: 25

Keyless Entity Types - EF Core still checks primary keys

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

Upvotes: 0

Views: 898

Answers (1)

Julia
Julia

Reputation: 25

Update Entity Framework to 3.0.1v solves a problem

Upvotes: 1

Related Questions