In case someone else is here with my problem installing DB First Entity Framework.
In short, I needed to overload the Entities constructor to accept the connection string, the reason is that I could use the Asp.Net Core dependency injection container, retrieving the connection string from appsettings.json, rather than magically getting it from App.config. file when calling the constructor without parameters.
I forgot to add calls to initialize my DbSets in a new overload. Thus, an automatically generated constructor without parameters looked something like this:
public MyEntities() : base("name=MyEntity") { Set1 = Set<MyDbSet1>(); Set2 = Set<MyDbSet2>(); }
And my new overload looked like this:
public MyEntities(string connectionString) : base(connectionString) { }
The solution was to add those initializers that the automatically generated code takes care of, a simple skipped step:
public MyEntities(string connectionString) : base(connectionString) { Set1 = Set<MyDbSet1>(); Set2 = Set<MyDbSet2>(); }
This really led me to a loop because some of the calls in our Respository that used DbContext worked fine (those that did not need these initialized DBSets), while others threw the runtime error described in the OP.
Franklin Tarter May 30 '18 at 16:56 2018-05-30 16:56
source share