我正在为使用 Entity Framework 的应用实现搜索功能。有几个可选字段用于搜索特定的数据库表/ View 。使用 EF 实现此类搜索的最佳方法是什么?存储过程?还是可以(实际上)仅使用 Linq 来完成?
最佳答案
处理可选搜索参数的常见模式是执行如下操作:
string p = null;
var q = from o in dataContext.Products
where ((o.Name == p) || (p == null))
select o;
关于c# - Entity Framework -动态sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1329784/