查询功能——“模糊查询”

撰写时间:2019年7月26日
在一些实际项目中——模糊查询这个功能往往能发挥很大的作用,而且模糊查询在我们手机、电脑上用来查找信息用得最多的一种搜索功能 。那么它主要就是用于一些与“数据”相关的信息,通过它可快速查找到我们想要的信息;它通常是用关键字模糊查找,所谓关键字就是关区信息中所包含的字符等等 。
所谓“模糊查询”,就是利用部分参数或者是字段查找到一些相关数据的方式 。比如说按姓名查询拿到某条用户信息,仅指定姓名的某个部分,如姓或者名字中的某个字或者它们的组合,都可以找出与他们相关的一些信息数据 。那么它的主要用来在我们已知信息少的情况下尽可能的找出我们所需要的数据信息 。查询关区信息中的某条信息我们怎么做呢?首先,先获取它的查询条件:我呢是根据关区的编码来查询关区的信息,然后呢就重载表格的数据,给他条件Where这是页面上的 。
下面我们一起来看一下这个例子:
控制器那边的就是要查询这个关区的所有的信息,多表的就要联表查询其他的表里面的信息(Join tb in +表名 on tb点那个表IDtb+ID)这样就可以联到其他的表和他的一些相关的信息和数据,如果想要倒序那就+tb+主表的ID 最后加一个倒序,如下图所示:
查询的完整代码如下:
public ActionResult SelectDistrict(LayuiTablePage layuiTablePage, string ZoneCoding){List listDistrict = (from tbDistrict in myModel.B_Districtjoin tbCustoms in myModel.B_Custom on tbDistrict.CustomsID equals tbCustoms.CustomsIDjoin tbDoorPoint in myModel.B_DoorPoint on tbDistrict.DoorPointID equals tbDoorPoint.DoorPointIDorderby tbDistrict.DistrictID descendingselect new DistrictVo{ZoneCoding = tbDistrict.ZoneCoding,//关区编码DistrictID = tbDistrict.DistrictID,//关区IDsDoorPointID = tbDistrict.DoorPointID,//门点IDCustomsID = tbDistrict.CustomsID,//海关IDCustomsName = tbCustoms.CustomsName,//海关名称ZoneEnglishName = tbDistrict.ZoneEnglishName,//英文名称DoorPointName = tbDoorPoint.DoorPointName,//门点名称Describe = tbDistrict.Describe,//描述Location = tbDistrict.Location,//地址ZoneInvalidation = tbDistrict.ZoneInvalidation,//是否启用Website = tbDistrict.Website,//网址ClosingTime1 = tbDistrict.ClosingTime.ToString(),//下班时间*/Workday2 = tbDistrict.Workday.ToString(),//上班时间Postcode = tbDistrict.Postcode,//邮编Fax = tbDistrict.Fax,//传真Email = tbDistrict.Email,//邮件LXman = tbDistrict.LXman,//联系人Telephone = tbDistrict.Telephone,//电话MobilePhone = tbDistrict.MobilePhone//手机}).ToList();//模糊查询if (!string.IsNullOrEmpty(ZoneCoding)){listDistrict = listDistrict.Where(m => m.ZoneCoding.Contains(ZoneCoding)).ToList();}//计算数据总条数int totalRow = listDistrict.Count();//提取数据List bdDistrict = listDistrict.Skip(layuiTablePage.GetStartIndex()).Take(layuiTablePage.limit).ToList();//实例化LayuiTableData layuiTableData = http://www.kingceram.com/post/new LayuiTableData();layuiTableData.count = totalRow;layuiTableData.data = http://www.kingceram.com/post/bdDistrict;return Json(layuiTableData, JsonRequestBehavior.AllowGet);}

查询功能——“模糊查询”

文章插图
下面的这句代码是最主要的模糊查询
//模糊查询if (!string.IsNullOrEmpty(ZoneCoding)){listDistrict = listDistrict.Where(m => m.ZoneCoding.Contains(ZoneCoding)).ToList();}
效果图如下图所示:
【查询功能——“模糊查询”】我是根据关区的编码来查询关区的信息的,下面我们可以看到有关于“J”的编码的关区信息查询得到的信息有两条,那么以上的就是我写的模糊查询 。当然了我们也可以用模糊查询来查其他我们需要的信息 。