Hi,
I Added CompanyDbContext to my project new to OriginalDbContex created by the template. I also regisetered it at OriginalEntityFrameworkCoreModule. It looks like this:
Configuration.Modules.AbpEfCore().AddDbContext<CompanyDbContext>(options =>
{
if (options.ExistingConnection != null)
{
CompanyDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
}
else
{
CompanyDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
}
});
The problem is that the
options
parameter always contains default connecion string... I tried to register it at startup.cs which did not work either.
services.AddDbContext<CompanyDbContext>(options=>
{
var connectionString=_appConfiguration["ConnectionStrings:CS_Test"];
options.UseSqlServer(connectionString);
});
Can you help me to obtain the CS_Test parameter please?
I also implemented IDesignTimeDbContextFactory<CompanyDbContext> the same as the OriginalFbContext has. But the comment above it says
/* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
Where is the problem then?
Thank you.
3 Answer(s)
-
0
Try the solution here: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1884#issuecomment-282092812
-
0
Thank you. I created my own ConnectionStringResolver. Unfortunaltely the configuration provided in ConfigurationManager did not contain the connection string from appsettings.json so I had to hard code id.
So be it... issue is resolved even though I am very disappointed or I did not get it correctly.
-
0
hi, don't get dissappointed :) how about this one?
var appsettingsjson = JObject.Parse(File.ReadAllText("appsettings.json")); var connectionStrings = (JObject)appsettingsjson["ConnectionStrings"]; var connectionString = connectionStrings.Property("Default").Value.ToString();