Including entity via OnModelCreating creates table but is not available in context
See original GitHub issueFile 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:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think the issue is poor documentation of using DbConext.Set!
@roji Thank you, I sent this to a new docs issue.