I am starting work with entity framework. Problem is that my OnModelCreating method is never called.
this is my context class:
public class TestContext : DbContext
{
public TestContext()
: base("name=TestDBConnectionString")
{ }
public DbSet<WorkItem> WorkItems { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
Connection string
<add name="TestDBConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=TestDB;Integrated Security=true"
providerName="System.Data.SqlClient"/>
I expect to go into OnModelCreating when I call:
using (var context = new TestContext())
{
}
Where I making mistake?
In my case this was happening because I had left the { get; set; } off my DBSet declaration. Took a while to figure that out!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With