Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net EntityDataSource上有多个Where参数?_Asp.net_Vb.net_Gridview_Entitydatasource - Fatal编程技术网

Asp.net EntityDataSource上有多个Where参数?

Asp.net EntityDataSource上有多个Where参数?,asp.net,vb.net,gridview,entitydatasource,Asp.net,Vb.net,Gridview,Entitydatasource,我有一个gridview,它使用实体数据源来填充自身。根据用户有权查看的内容,我希望gridview实现where子句。在最低访问级别,用户只能看到自己。为此,我实现了以下代码行: EmployeeEntityDataSource.Where = "it.Person_ID = " + selectQuery.ToString() 这将成功地将gridview中的数据减少到一个合适的用户。如果用户在访问中有下一步,他们应该能够看到自己以及为他们工作的所有员工。我已经成功地创建了一个员工个人ID

我有一个gridview,它使用实体数据源来填充自身。根据用户有权查看的内容,我希望gridview实现where子句。在最低访问级别,用户只能看到自己。为此,我实现了以下代码行:

EmployeeEntityDataSource.Where = "it.Person_ID = " + selectQuery.ToString()
这将成功地将gridview中的数据减少到一个合适的用户。如果用户在访问中有下一步,他们应该能够看到自己以及为他们工作的所有员工。我已经成功地创建了一个员工个人ID列表,我正在尝试筛选我的gridview,以便如果gridview中的个人ID列与我列表中的一个个人ID匹配,它就会显示出来

我尝试了以下代码:

一,

我在这里得到的错误是T列表无法转换为WebControl.Parameter


如何正确创建WHERE语句,将gridview的it.Person\u ID与我的列表中名为employeeList的每个元素进行比较?

我认为in语句应该满足您的需要。类似这样的事情-

string employeeIDs = string.Join(",", employeeList.ToList());
EmployeeEntityDataSource.Where = String.Format("it.Person_ID IN ({0})", employeeIDs);

或者,您可能需要遍历列表来创建EmployeeID字符串,具体取决于我们在这里处理的类型

显然,当我说我的第一段代码不起作用时,我撒谎了。问题是我没有正确地生成大量的或声明

从我记忆中我最初生成的语句就是它。Column=ID1或ID2或ID3,依此类推

如果创建的语句是it.Column=ID1或it.Column=ID2或it.Column=ID3,依此类推,这将创建一个工作正常的语句

在我当前项目中工作的代码是:

For Each employee In employeeList
    If count2 <> count Then
        whereString += "it.Person_ID = " + employee.ToString() + " OR "
        count2 += 1
    Else
        whereString += "it.Person_ID = " + employee.ToString()
    End If
Next

EmployeeEntityDataSource.Where = whereString

我编辑了您的代码以使用Visual Basic,我认为这是针对C Dim EmployeeID的,因为String=String.Join,,employeeList EmployeeEntityDataSource.Where=String.Formatit.Person_ID在{0}中,EmployeeID我得到错误查询语法无效。近期术语“,”第8行第21列。看起来这可能是实体框架中固有的问题。看看这个:根据第二个回复,他们似乎用EF4实现了开箱即用。我很难弄清楚如何在where语句中获取我的员工列表,因为它需要一个字符串,我想向它传递一个变量。请使用此URL使in语句正常工作
string employeeIDs = string.Join(",", employeeList.ToList());
EmployeeEntityDataSource.Where = String.Format("it.Person_ID IN ({0})", employeeIDs);
For Each employee In employeeList
    If count2 <> count Then
        whereString += "it.Person_ID = " + employee.ToString() + " OR "
        count2 += 1
    Else
        whereString += "it.Person_ID = " + employee.ToString()
    End If
Next

EmployeeEntityDataSource.Where = whereString