Home
Options

Disable CreateIfNotExists

Hi,

I signed up to ask for help solving a problem but found the answer on stackoverflow, so I thought I'd share the problem and solution.

I have a DbContext that I use to query synonyms instead of tables (its a long story) and called "Database.SetInitializer(null);" to disable the CreateIfNotExists call as EF can't find the tables it expects and tries to create them but the objects name already exists so fails.

Using LinqPad I created a DbContext connection using the DLL I created for my project and found whilst using LinqPad EF tried to create the tables and failed.

The problem was caused by LinqPad subclassing my DbContext class so as a result the default initialiser was used instead of not using one at all as specified for my class.

To solve the issue I used reflection as per the answer in this (http://stackoverflow.com/a/23119271) stackoverflow answer to call generic method Database.SetInitializer with the subclass type created by LinqPad.

No need to respond its just here in case I forget or somebody else has the same problem ( assuming they can find it :) ).
Sign In or Register to comment.