一.数据库前提
-
两张表的字段条数相同
-
两张表的数据类型相同
二.关系如下 :医嘱明细表里字段医嘱项目ID,它代表药品id和检查项目id然后通过医嘱明细表里的字段医嘱项目类型用枚举的方式来区分,1为药品2为检查项目。合并表要用到Union,同时要建一个实体类让它们在控制器的名称和实体类的相同。
控制器代码:
public ActionResult DoctorManagetion(LayuiTablePage layuiTablePage)
{
//1、连接药品
var listDrug = (from tbDoctoradvice
in myModels.B_Doctoradvice
join tbChekin in
myModels.B_Checkin on tbDoctoradvice.CheckinID equals tbChekin.CheckinID
join
tbDoctoradviceDtail in myModels.B_DoctoradviceDetail on
tbDoctoradvice.DoctoradviceID equals tbDoctoradviceDtail.DoctoradviceID
join tbDrug in myModels.B_Drug
on tbDoctoradviceDtail.DoctoradviceItemID equals tbDrug.DrugID