В ASP. NET Ядро Я пытаюсь добавить новый столбец в свою базу данных. Я создал модель
public class Courier
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Prescription> Prescriptions { get; set; }
}
И в моем классе рецептов
public class Prescription
{
public int CourierId { get;set; }
public virtual Courier Courier { get;set; }
}
В моем классе dbcontext
я добавил public DbSet<Courier> Couriers { get;set; }
В основном я создаю рецепт в своем patients
контроллер, и он заполняет все необходимые свойства для рецепта, и я пытаюсь добавить свойство Courier
к Prescription
, но теперь, когда я нажимаю на Prescriptions/Index
или Patients/Details/id
или пытаюсь go к Couriers/Index
Я получаю сообщение об ошибке
SQLException: Invalid column name 'CourierId'
Patients
контроллер
[HttpPost]
public IActionResult CreatePrescription(PatientDetailsViewModel model)
{
var user = _userManager.GetUserId(User);
Prescription prescription = new Prescription
{
MedicationId = model.Prescription.MedicationId,
RxNumber = model.Prescription.RxNumber,
Frequency = model.Prescription.Frequency,
Quantity = model.Prescription.Quantity,
FolderStatusId = model.Prescription.FolderStatusId,
RefillsRemaining = model.Prescription.RefillsRemaining,
PrescriberId = model.Prescription.PrescriberId,
OriginalRxDate = model.Prescription.OriginalRxDate,
ExpiryDate = model.Prescription.ExpiryDate,
DateFilled = model.Prescription.DateFilled,
DeliveryDate = model.Prescription.DeliveryDate,
DeliveryTime = model.Prescription.DeliveryTime,
BillDate = model.Prescription.BillDate,
CourierId = model.Prescription.CourierId,
PatientId = model.Patient.Id,
ApplicationUserId = user,
IsActive = true
};
_context.Add(prescription);
_context.SaveChanges();
return RedirectToAction("Index", "Patients");
}
И в моем Couriers
контроллере
public IActionResult Index()
{
//return View(await _context.Courier.ToListAsync());
return View(_context.Couriers.ToList());
}
Я хотел бы иметь возможность добавить CourierId
в таблицу Prescriptions
и отобразить для пользователя Courier.Name
, но мне нужно исправить ошибку с недопустимым именем столбца?