Is there a intutive way for me to grab two collumns from another Table in the database while I am creating something in another table? I need to be able to grab a two ints from Table 1 so I can create a number on Table 2. Is there any tutorial or video for that? Should I manually create a MySQL connection on my Create function? Or is there a way to hook on the connection already there? On the tutorial we grab the userID with "var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;" is there a way to do the same with other tables?
Yes you ca do that using partial OnXXXCreated method of the controller:
public partial class OrdersController
{
partial void OnOrderCreated(Models.Sample.Order item)
{
// Get DbContext
var dbContext = (SampleContext)HttpContext.RequestServices.GetService(typeof(SampleContext));
// Query some data related to current item for insert
var detailsForOrder = dbContext.OrderDetails.Where(od => od.OrderId == item.Id);
...
}
}
When I try doing the same with:
namespace Cnpj.Controllers.Cnpj
{
using Models.Cnpj;
using Models;
using Data;
[Authorize(AuthenticationSchemes = "Bearer")]
public partial class T04RequisicosController
{
partial void OnT04RequisicoCreated(Models.Cnpj.T04Requisico item)
{
var dbContext = (CnpjContext)HttpContext.RequestServices.GetService(typeof(CnpjContext));
var test2 = dbContext.T80ListEstados.Where(od => od.UF == "SP");
}
}
}
The Where function seems to not exist, resulting in failure... any thing I am doing wrong in specific?