Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can still define the connection string in the DBContext in EF6.</p> <pre><code>public class ApplicationDbContext : DbContext { public ApplicationDbContext() : base(@"Your connection string here") { } // Rest of your DbContext code } </code></pre> <p>But hard coding a connection string in there isn't very versatile. Even though your <code>DbContext</code> will be in it's own dll, it can still read the <code>app.config</code> or <code>web.config</code> of your primary project if it is in the same solution (and I'm fairly sure it will work even if you add your <code>DbContext</code> dll as a reference). </p> <p>Just add a reference to <code>System.Configuration</code> in your <code>DbContext</code> project, and then you can get at the connection string with either <code>ConfigurationManager.ConnectionStrings["MyConnectionStringName"].ConnectionString</code> or <code>ConfigurationManager.AppSettings["MyConnectionStringName"]</code></p> <p>And you would store the connection string in your primary applications <code>web.config</code> in the <code>&lt;connectionStrings&gt;</code> section OR in the 'app.config' in the <code>&lt;appSettings&gt;</code> section</p> <p>Note that if you do it this way (by reading from <code>web.config</code> or <code>app.config</code>), you should change your <code>DbContext</code> code accordingly:</p> <pre><code>public class ApplicationDbContext : DbContext { public ApplicationDbContext() : base("MyConnectionStringName") { } // Rest of your DbContext code } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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