I am starting to lean asp.net core 3 and I have an issue at present. I am trying to share my db context like I used to through a .net core dll but I have an error.
I have the following declared in my class.
// This method gets called by the runtime. Use this method to add services to e container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddDbContext<DbContext_Model>(options =>
options.UseSqlServer(Configuration.GetConnectionString("AppliedContext")));
}
The db context which I have in my core dll project solution.
public class DbContext_Model: DbContext
{
public DbContext_Model(DbContextOptions<DbContext_Model> options)
: base(options)
{ }
public DbSet<Customer> Customer { get; set; }
public DbSet<Policys> Policys { get; set; }
}
I have declared my connection string below with password masked
"ConnectionStrings": { "AppliedContext": "Server=DESKTOP\MSSQLSERVER2017;Database=Systems;User Id=sa;Password=xxxxx;MultipleActiveResultSets=true"
But When I do Add-Migration InitalCreate I get this error.
Unable to create an object of type 'DbContext_Model'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Is sharing of the context no longer allowed between .net core libarys and a web site ?
Edit 2
Please see screen shot which shows I am selecting the correct project.
Edit 3
That seemed to cause an another error the suggestion below. So I added the nugets in for the json tooling but still get this error.
dotnet ef migrations add InitialCreate System.MissingMethodException: Method not found: 'System.Text.Json.JsonDocument System.Text.Json.JsonDocument.Parse(System.IO.Stream, System.Text.Json.JsonReaderOptions)'. at Microsoft.EntityFrameworkCore.Tools.RootCommand.Execute() at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.b__0() at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args) Method not found: 'System.Text.Json.JsonDocument System.Text.Json.JsonDocument.Parse(System.IO.Stream, System.Text.Json.JsonReaderOptions)'. PM> dotnet ef migrations add InitialCreate