EntityDataSource凡在VB.NET条款 [英] EntityDataSource Where Clause in VB.NET
问题描述
我有一个绑定到一个GridView在我的网页上entitydatasource。
I have a entitydatasource bound to a gridview on my webpage.
在code后面,我能够过滤和显示我用entitydatasource的WHERE语句要到GridView。其中通过使用一个或大或声明,但更合乎逻辑的语句中不工作我,语句的过滤器。
In the code behind, I am able to filter and display what I want to the gridview using the WHERE statements of the entitydatasource. One of my where statements filters by using a large OR statement, but the much more logical IN statement does not work.
例如我有1-9名员工,我想选择员工1,4,和7 SQL我能得到这个两种方式:
For example I have employees 1-9 and I want to select employees 1, 4, and 7. In SQL I can get this two ways:
1
SELECT * FROM table WHERE EmployeeID = 1 OR EmployeeID = 4 OR EmployeeID = 7
2
SELECT * FROM table WHERE EmployeeID IN (1,4,7)
这两个语句完全正常工作,我在SQL
Both of these statements work perfectly fine for me in SQL
在使用EF,唯一的选择1作品选择那些特殊的员工。为了创建这个说法,我有一个for循环,创建一个whereString,最终这样看:
When using the EF, only option 1 works for selecting those particular employees. In order to create this statement, I have a for loop that creates a whereString that end up looking like this:
whereString = "it.EmployeeID = 1 OR it.EmployeeID = 4 OR it.EmployeeID = 7"
EntityDataSource.Where = whereString
如果设置我的whereString等于该
If I set my whereString equal to this
whereString = "it.EmployeeID IN (1,4,7)"
这是行不通的。为什么这其中,模仿在SQL $ C $所使用的格式条款C--不行?
it does not work. Why does this where clause that mimics the format used in the SQL code not work?
推荐答案
在IN子句为EntityDataSource.Where需要花括号,而不是括号:
The "IN clause" for EntityDataSource.Where requires curly braces, rather than parentheses:
whereString = "it.EmployeeID IN {1,4,7}"
这篇关于EntityDataSource凡在VB.NET条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!