title: Why LinqPad return The name 'ModelName' does not exist in the current context error?
body: <p>I have a <strong>Asp.net MVC - C#</strong> project and want to use <strong>LINQPad</strong> to test some Entity Framework statements of it before use them in the project.</p>
  
  <p>The project has different class libraries such as</p>
  
  <ul>
  <li><strong>DAL</strong> (include the <code>ApplicationDbContext</code> class) </li>
  <li><strong>Domain Classes</strong> (models)</li>
  </ul>
  
  <p><strong>A)</strong> I added an <strong>EF Connection</strong> to the <strong>DAL</strong> in <em>LINQPad</em> and it loaded all of the entities in the left tree in its window successfully. <em>[See the bellow image]</em></p>
  
  <p><a href="https://i.stack.imgur.com/jrYvW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jrYvW.jpg" alt="enter image description here"></a></p>
  
  <p><strong>B)</strong> Also i added the some required references from <em>LINQPad Query</em> to the following DLLs:</p>
  
  <ul>
  <li>DAL dll</li>
  <li>Domain Classes dll</li>
  <li>Microsoft.AspNet.Identity.Core.dll</li>
  <li>EntityFramework.dll</li>
  </ul>
  
  <hr>
  
  <h2>But »</h2>
  
  <p>When i right click on an entity in the left tree and select each option, it show this error:</p>
  
  <blockquote>
    <p>The name '[Conceptual_Model_Name]' does not exist in the current context</p>
  </blockquote>
  
  <p><strong>Why?</strong> 
  <strong>How can i resolve this problem?</strong></p>
  
  <hr>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>In the <strong><code>OnModelCreating</code></strong> method of <code>ApplicationDbContext</code> class i call the following method to <strong>add entities to the <code>DbContext</code> dynamically</strong>. </p>
  
  <pre><code>    public void LoadEntities(Assembly asm, DbModelBuilder modelBuilder, string nameSpace)
      {
          var entityTypes = asm.GetTypes()
              .Where(type =&gt; type.BaseType != null &amp;&amp;
                             type.Namespace == nameSpace &amp;&amp;
                             type.BaseType == null)
              .ToList();
  
          var entityMethod = typeof(DbModelBuilder).GetMethod("Entity");
          entityTypes.ForEach(type =&gt; entityMethod.MakeGenericMethod(type).Invoke(modelBuilder, new object[] { }));
      }
  </code></pre>
  
  <p>I call it with this line of code:</p>
  
  <pre><code>LoadEntities(typeof(AppUser).GetTypeInfo().Assembly, modelBuilder, "DomainClasses.Entities");
  </code></pre>
  
  <p>Is it possible the reason be related to this dynamic loading of models?</p>