3

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.

TomTom
  • 61,059
  • 10
  • 88
  • 148

1 Answers1

3

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.

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • +1. That was my starting point. I managed to set up a homade EntityConnection so that the model is loaded properly from the file. – TomTom Dec 01 '12 at 00:42