Why LinqPad return The name 'ModelName' does not exist in the current context error?
asp.net-mvc, c#, entity-framework, linqpad
Solution
I solved it myself !
The suspicion that i wrote about it in the question, was correct. As I wrote in the question i add the entities to the `DbContext` as dynamically but now i changed it to the static way like this:
// Add this property to the ApplicationDbContext class
public virtual DbSet<Consumption> Consumptions { get; set; }
Now when i use `Consumptions` property in `LINQPad` it works...
Problem
I have a Asp.net MVC - C# project and want to use LINQPad to test some Entity Framework statements of it before use them in the project. The project has different class libraries such as - DAL (include the `ApplicationDbContext` class) - Domain Classes (models) A) I added an EF Connection to the DAL in LINQPad and it loaded all of the entities in the left tree in its window successfully. [See the bellow image] B) Also i added the some required references from LINQPad Query to the following DLLs: - DAL dll - Domain Classes dll - Microsoft.AspNet.Identity.Core.dll - EntityFramework.dll But » When i right click on an entity in the left tree and select each option, it show this error: The name '[Conceptual_Model_Name]' does not exist in the current context Why? How can i resolve this problem? Edit 1: In the `OnModelCreating` method of `ApplicationDbContext` class i call the following method to add entities to the `DbContext` dynamically. ``` public void LoadEntities(Assembly asm, DbModelBuilder modelBuilder, string nameSpace) { var entityTypes = asm.GetTypes() .Where(type => type.BaseType != null && type.Namespace == nameSpace && type.BaseType == null) .ToList(); var entityMethod = typeof(DbModelBuilder).GetMethod("Entity"); entityTypes.ForEach(type => entityMethod.MakeGenericMethod(type).Invoke(modelBuilder, new object[] { })); } ``` I call it with this line of code: ``` LoadEntities(typeof(AppUser).GetTypeInfo().Assembly, modelBuilder, "DomainClasses.Entities"); ``` Is it possible the reason be related to this dynamic loading of models?