I have a controller class called SearchController.cs
I have a DBContext call to my a SQL Database inside the controller:
namespace Rescue.Exchange.API.Controllers
{
[AllowAnonymous]
//This controller will Post all PCR data from the NEMSISv3 database to the Resuce Exchange landing page.
[Route("api/[controller]")]
[ApiController]
public class SearchController : UserIdentityController
{
private readonly NEMSISv3Context _context;
public SearchController(NEMSISv3Context context)
{
_context = context;
}
//Do Something with the database call _context
//I want to do something with my second database call, I guess _contextLog?
}
}How can I use another DBContext inside the same controller to call to a separate database?
I have the following DBContext in my startup:
services.AddDbContext<NEMSISv3Context>(options =>
options.UseSqlServer(Configuration.GetConnectionString("SearchConnection")));
services.AddDbContext<ExchangeContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("RescueExchangeConnection")));If someone could please show me how the code would work that would be great. I am fairly new to C# and .NET Core.