Should Entity Framework Core database first OnModelCreating method run

Luiso Source

I am building a new asp net core app and need to support a legacy database so I've come across this article where they pretty much explain how to get everything up and working DB first. I however have some questions, back when using EF 6 if you went in DB/Model First the generated DbContext your had this:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    throw new UnintentionalCodeFirstException();

so your DB wouldn't get modified by mistake, I just generated the ef-core context for the same DB and in the OnModelCreating method I have all the config that should be in place if it was created code first, I saw this and tried to mimic the above behavior and, surprise, surprise, got an exception, the same one I was throwing.

So my questions are:

Is is necessary to run that method with all it's config?
If I end up running it and change my model accidentally will it modify my DB?
If I just let me method run, not doing nothing, will I still be able to use the generated classes and DbContext?



comments powered by Disqus