question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Including entity via OnModelCreating creates table but is not available in context

See original GitHub issue

File a bug

The docs page for Entity Types indicates that entities can be included in a few ways, including using it in OnModelCreating().

The table is created, however the entity cannot be accessed via the context.

Include your code

Include entity type

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<AuditEntry>();
}

Cannot access entity type

    var auditEntries = context.AuditEntry.ToList(); // compile time error

Here is the error:

‘Context’ does not contain a definition for ‘AuditEntry’ and no accessible extension method ‘AuditEntry’ accepting a first argument of type ‘Context’ could be found

Include provider and version information

EF Core version: 5.0.4 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 5.0 Operating system: macOS 10.15.7 IDE: Visual Studio for Mac 8.10 Preview 1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikEJcommented, Apr 6, 2021

I think the issue is poor documentation of using DbConext.Set!

0reactions
mrlifecommented, Apr 6, 2021

@roji Thank you, I sent this to a new docs issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Entity Created OnModelCreating is not accessible in ...
1 Answer 1 · Tried that but not getting any results from the bridge table. Im getting nothing. The count is 0. Im...
Read more >
Entity Types - EF Core
How to configure and map entity types using Entity Framework Core. ... EF Core can create tables for your entities via migrations.
Read more >
Creating and Configuring a Model - EF Core
Overview of creating and configuring a Entity Framework Core model via Fluent API, Data Annotations and conventions.
Read more >
A Cleaner Way To Do Entity Configuration With EF Core
By Entity Configurations, I mean doing a code first design and being able to mark fields as “Required”, or limit their length, or...
Read more >
Don't let Entity Framework call the shots - Fear of Oblivion
To demonstrate these things, I have created a tiny sample that should show the most commons “issues” I keep seeing. The database looks...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found