Note that there are some explanatory texts on larger screens.

plurals
  1. POThe entity type <type> is not part of the model for the current context
    text
    copied!<p>I am getting into the Entity Framework, but I am unsure if I am missing a critical point in the code-first approach.</p> <p>I am using a generic repository pattern based on the code from <a href="https://genericunitofworkandrepositories.codeplex.com/" rel="noreferrer">https://genericunitofworkandrepositories.codeplex.com/</a> and have created my entities.</p> <p>But when I try to access or modify the entity I run into the following:</p> <blockquote> <p>System.InvalidOperationException: The entity type Estate is not part of the model for the current context.</p> </blockquote> <p>It happens when I am trying to access it from my repository:</p> <pre><code>public virtual void Insert(TEntity entity) { ((IObjectState)entity).ObjectState = ObjectState.Added; _dbSet.Attach(entity); // &lt;-- The error occurs here _context.SyncObjectState(entity); } </code></pre> <p>The database (./SQLEXPRESS) is created just fine, but the entities (tables) is just not created on startup. </p> <p>I am wondering if I need to explicit set the mapping of the entities? Is EF not able to this by its own? </p> <p>My Entity is:</p> <pre><code>public class Estate : EntityBase { public int EstateId { get; set; } public string Name { get; set; } } </code></pre> <p>My context is as so:</p> <pre><code>public partial class DimensionWebDbContext : DbContextBase // DbContextBase inherits DbContext { public DimensionWebDbContext() : base("DimensionWebContext") { Database.SetInitializer&lt;DimensionWebDbContext&gt;(new CreateDatabaseIfNotExists&lt;DimensionWebDbContext&gt;()); Configuration.ProxyCreationEnabled = false; } public new IDbSet&lt;T&gt; Set&lt;T&gt;() where T : class { return base.Set&lt;T&gt;(); } } </code></pre> <p>Is there any specific reason why this error occurs? I have tried enable migrations and enable automatic migrations without any help either.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload