我有一个查询,我从一些选项中编写它,比如
#include <dirent.h>
#include <vector>
#include <cstring>
void GetReqDirs(const std::string& path, std::vector<string>& files,const bool showHiddenDirs = false){
DIR *dpdf;
struct dirent *epdf;
dpdf = opendir(path.c_str());
if (dpdf != NULL){
while ((epdf = readdir(dpdf)) != NULL){
if(showHiddenDirs ? (epdf->d_type==DT_DIR && string(epdf->d_name) != ".." && string(epdf->d_name) != "." ) : (epdf->d_type==DT_DIR && strstr(epdf->d_name,"..") == NULL && strstr(epdf->d_name,".") == NULL ) ){
GetReqDirs(path+epdf->d_name+"/",files, showHiddenDirs);
}
if(epdf->d_type==DT_REG){
files.push_back(path+epdf->d_name);
}
}
}
closedir(dpdf);
}
我怎样才能在一次尝试中针对LINQ over entity-framework-6做到这一点?
答案 0 :(得分:0)
是的,你可以。你可以链接几个。所有操作。所以你可以像写
一样写smt var set = MySet;
if (cond_1) {
set = set.Where(a=>...);
}
if (cond_2) {
set = set.Where(a=>...);
}
set.ToList()
等
答案 1 :(得分:0)
您可以通过使用IQueryAble来实现。 这个例子可以帮到你:
//Define your query without executing it.
IQueryable<YourEntityType> query= (from s in Context.MyTable select s);
if(options1)
//Add a where clause to your IQueryable
query= query.Where(p=> p.SomeProperty == "Something");
if(options2)
//Add another where clause to your IQueryable
query= query.Where(p=> p.SomeProperty == "Something else");
//Executes the query depending your options.
var Result = query.ToList();