本文介绍了如何在where子句中创建具有多个条件的动态查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! public object SearchInfo(DateTime duedate, int customerid, int billtypeid, int providerid,字符串 cityname,字符串 isaname,字符串 buildingname) { 尝试 { context = new MGLEntities(); var query = 来自 cb context.tbl_CustomerBills join c in context.tbl_Customer on cb.CustomerID equals c。 CustomerID 其中 // 这里我想要根据搜索信息中的参数添加条件。假设,用户只输入duedate,条件应为cb.DueDate == duedate 如果用户输入customerid和billtypeid,则条件应为 c.CustID == customerid&& cb.Billtypeid == billtypeid 查询应该更改动态根据收到的参数。请如果任何人都知道解决方案然后建议我。谢谢 提前 选择 new { c.CName, cb.DueDate, cb.CustomerID } ; return 查询; } catch (例外){ return 空; } } 解决方案 public object SearchInfo(DateTime duedate, int customerid, int billtypeid, int providerid, string cityname, string areaname, string buildingname){try{context = new MGLEntities();var query = from cb in context.tbl_CustomerBillsjoin c in context.tbl_Customer on cb.CustomerID equals c.CustomerIDwhere // here I want to add condition according to parameters in search info.Suppose, only duedate is entered by user then condition should be "cb.DueDate == duedate"If user enters customerid and billtypeid then condition should be "c.CustID == customerid && cb.Billtypeid == billtypeid"query should change dynamically according to received parameters.Please if anyone knows the solution then suggest me. Thanks in advanceselect new{c.CName,cb.DueDate,cb.CustomerID};return query;}catch (Exception) { return null; }} 解决方案 这篇关于如何在where子句中创建具有多个条件的动态查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 04:39
查看更多