Search code examples
reverse-engineeringentity-framework-core

Entity Framework Reverse Engineering OnModelCreating


This is a very simple question...

I have reverse engineered an existing database with entity framework core, it works well and I have my classes defined, it has also created on the OnModelCreating event thousands and thousands of line of code detailing all the indexes references etc...

Do I need this code? I am not planning to modify the db schema just simply reading data and updating data from an api, can I comment out all of these lines?


Solution

  • You mean protected override void OnModelCreating(ModelBuilder modelBuilder) method in you DbContext class?

    Yes, you need it.

    It contains description of references between your entities - it's important for EF to build correct SQL queries.

    It is possible to optimize/minimize it (by removing some lines that do not important for your area), but it's manual operation, if you have enough time...