*
In a project , Basically every page needs to query data ? So how to achieve it , today , Let's learn about multi table query . On multi table query , Naturally, we think of the multi table query in the database , The query in the database is actually the same as the query in the database MVC The query in is very similar .
Database query :
SELECT Column name FROM Table name ;
give an example :
MVC Query for :
of course , If it's multiple tables , Right here from Let's connect the relationships between tables , In the back Select Find the fields you need . Take the following example :
public ActionResult SeacherCheck(LayuiTablePage layuiTablePage, int MedMesID)
{
var listEntry = from tbMedHouseDetail in myModels.SYS_MedHouseDetail
join tbMedMes in myModels.SYS_MedMes on
tbMedHouseDetail.MedMesIDequals tbMedMes.MedMesID
join tbManufacturer in myModels.SYS_Manufacturer on
tbMedMes.ManufacturerIDequals tbManufacturer.ManufacturerID
join tbMedHouse in myModels.SYS_MedHouse on
tbMedHouseDetail.MedHouseIDequals tbMedHouse.MedHouseID
orderby tbMedHouseDetail.MedHouseDatileID descending
select new Apply
{
MedMesID = tbMedMes.MedMesID,
MedHouseDatileID = tbMedHouseDetail.MedHouseDatileID,
ManufacturerID = tbManufacturer.ManufacturerID,
MedName = tbMedMes.MedName,
Repertory = tbMedHouseDetail.Repertory,
MedicineUnit = tbMedMes.MedicineUnit,
MedicineSpecificat = tbMedMes.MedicineSpecificat,
MedicineDate = tbMedMes.MedicineDate,
MedicineValidity = tbMedMes.MedicineValidity,
MedHouseName = tbMedHouse.MedHouseName,
ManufacturerName = tbManufacturer.ManufacturerName
};
var intTotalRow = listReturn.Count();
List<Apply> list =
listReturn.Skip(layuiTablePage.GetStartIndex()).Take(layuiTablePage.limit).ToList();
// Calling the paging wrapper class
LayuiTableData<Apply> layuiTableDate = new LayuiTableData<Apply>();
layuiTableDate.count = intTotalRow; // Total rows
layuiTableDate.data = list; // Specific display data
return Json(layuiTableDate, JsonRequestBehavior.AllowGet);
}
*
Since there are many tables , Then it may not escape, it may appear conditional screening , Here is the code for conditional filtering , But don't forget to give it a parameter when writing conditional filter , When transferring page values , Don't use links URL pattern , It must be replaced by data pattern ( Limited in use Layui Form time )
if (MedMesID > 0)
{
istReturn = listReturn.Where(m => m.MedMesID == MedMesID);
}
Technology