如何解决如何从 ASP.NET Core 3.1 Identity 中的 IdentityUser 类添加关系? 代码优先
我有一个 Asp.Net Core MVC 3.1 项目。我想使用代码优先技术加入预约表和患者表,但外键列为空。
我的病人班;
public class Patient : IdentityUser
{
[NotMapped]
public List<Appointment> Appointments { get; set; }
}
还有我的Appointment课,我和病人和预约是一对多的关系。
public class Appointment
{
[Key]
public int ID { get; set; }
public string PatientID { get; set; }
public Patient Patient { get; set; }
}
如果我向外键添加“必需”注释不保存约会。
public Result<AppointmentVM> CreateAppointment(AppointmentVM model)
{
if (model != null)
{
try
{
var appointment = _mapper.Map<AppointmentVM,Appointment>(model);
_unitOfWork.appointmentRepository.Add(appointment);
_unitOfWork.Save();
return new Result<AppointmentVM>(true,"Successful");
}
catch (Exception ex)
{
return new Result<AppointmentVM>(false,"Error" + ex.Message.ToString());
}
}
else
return new Result<AppointmentVM>(false,"Not null");
}
我该如何解决这个问题?
public class AppointmentVM
{
public int AppointmentID { get; set; }
public string PatientID { get; set; }
public PatientVM Patient { get; set; }
}
public class AppointmentRepository : Repository<Appointment>,IAppointmentRepository
{
private readonly ClinicContext _ctx;
public AppointmentRepository(ClinicContext ctx) : base(ctx)
{
_ctx = ctx;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。