c# - Adding DbContextOptions in Startup.cs not registering data store -
my problem below code not register data store during startup. specific "error" statement in response application:
an unhandled exception occurred while processing request. invalidoperationexception: no data stores configured. configure data store overriding onconfiguring in dbcontext class or in adddbcontext method when setting services. microsoft.data.entity.storage.datastoreselector.selectdatastore(serviceprovidersource providersource)
in configureservices(iservicecollection services) trying specify dbcontextoptions dbcontext in lambda. code:
services.addentityframework(configuration) .addsqlserver() .adddbcontext<mydbcontext>( options => options.usesqlserver(configuration.get("data:defaultconnection:connectionstring")) );
in dbcontext, have constructor sends option base, code:
public mycontext(dbcontextoptions options) : base(options) { }
my configuration file config.json, read @ startup, contains connectionstring:
"data": { "defaultconnection": { "connectionstring": "server=(localdb)\\mssqllocaldb;database=mydbname;trusted_connection=true;multipleactiveresultsets=true;" } }
i have used
protected override void onconfiguring(dbcontextoptions options) { options.usesqlserver(startup.configuration.get("data:defaultconnection:connectionstring")); }
in dbcontext successfully. registers data store , works properly, i'd rather use lambda way.
if there more information needed, i'll provide it.
are injecting context controller or wherever using it? discovered if try new context instead of injecting it, not use configuration specified in startup.cs
Comments
Post a Comment