Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code First code generation trying to create the model?

Moving to Entity Framework 5, model first (due to the database being complex and being maintained separately). Importing the database, using the new DbContext code generator.

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

is generated and triggered when I manually generate the connection - which I have to (our connection setups are in a separate config file).

The message reads:

Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.

What the?

How can I suppress this? I do not want entity framework to do ANYTHING with the database schema, but I want to be able to USE the database, obviously.

like image 783
TomTom Avatar asked Dec 01 '25 15:12

TomTom


1 Answers

You want to read this: http://blog.oneunicorn.com/2012/02/26/dont-use-code-first-by-mistake/ It explains what's going on there and why you get this exception.

like image 97
Pawel Avatar answered Dec 04 '25 12:12

Pawel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!