问题描述
我有一个 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 (将#修改为@)