Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You showed us your <em>real</em> <code>DbContext</code>. You didn't show us the <em>phony</em> <code>DbContext</code> that exists only for DTO metadata generation. </p> <p>I was expecting something like</p> <pre><code>// notice the "Dto" in the class name internal class LifeAuditDbDtoContext : DbContext { // class constructor static LifeAuditDbDtoContext() { Database.SetInitializer&lt;LifeAuditDbDtoContext&gt;(null); } // instance constructor public LifeAuditDbDtoContext() : base("Dummy") { /// stuff } } </code></pre> <p><strong>This Dto version is the <code>DbContext</code> that needs the null initializer for sure!</strong></p> <h3>Still not working?</h3> <p>Sometimes I think I have to give EF a phony connection string even if the initializer is null. </p> <blockquote> <p>I'm not sure why and this could be voodoo.</p> </blockquote> <p>Try this and let us know if it works for you (note the name of string and the db is "dummy". The dummy database should not exist nor be created):</p> <pre><code>&lt;connectionStrings&gt; &lt;add name="Dummy" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\dummy.mdf;Initial Catalog=dummy;Integrated Security=True" providerName="System.Data.SqlClient" /&gt; ... other real strings ... </code></pre> <p></p> <p>Of course you could supply the real connection string name instead and dispense with the phony. The null initializer ensures that the app will not re-initialize the database. But personally, if EF is looking for a database connection string for this dummy <code>DbContext</code>, I don't want it to go anywhere near my real database.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload