我想在用户输入文本框中的关键字时向用户提供数据库表中的项目列表。我现在遇到的问题是用户可以输入多个关键字,并且我希望能够仅执行一次往返数据库并返回匹配多个关键字(一个OR操作)的结果。有没有办法执行这样的任务,而不必每个关键字都击中数据库?“Where In”with linq to sql
0
A
回答
1
我发现了一个post,提供一个漂亮很好的解决方案,我试图实现。感谢您的帮助!
0
我发现this page当试图弄清楚LINQ
在C#中的东西时非常有用。这表明the following syntax:
var results = from Item i in myCollectionOfItems
where i.OneThing = aGoodThing || i.SomeStuff != theBadStuff
select i;
编辑:对不起,误解了这个问题 - 我已经更新,以匹配一个OR
操作请求。 (我找不到参照页||
语法,但我相信它会奏效。它compiles on my machine ...
5
载有()是你的朋友。
List<string> keywords = new List<string>();
keywords.Add("foo");
keywords.Add("bar");
var results = from item in db.Table
where keywords.Contains(item.Description)
select item;
...给你
WHERE [t0].[Description] IN (@p0, @p1)
0
记号化你的输出你的关键字搜索。
那么你可以不断地说或者在WHERE条件C#(||运算符)。
即
var query = from row in mytable
where (row.column == a) || (row.column == b) || //.... etc
select row
0
你可以试试:
List<string> keywords = new List<string>();
keywords.Add("foo");
keywords.Add("bar");
var results = from item in db.Table
where keywords.Exists(k => item.Description.Contains(k))
select item;
但我不知道它会转换成SQL ...
相关问题
- 1. LINQ to SQL WHERE“IN”
- 2. LINQ to SQL - How to“Where ... in ...”
- 3. LINQ-to-SQL IN()
- 4. LINQ to Dataset - 相当于sql(where ... in ...)
- 5. IQueryable动态“WHERE IN”(LINQ to SQL)
- 6. LINQ to SQL in and not in
- 7. Signin in Linq to Sql?
- 8. linq to SQL OnLoaded()with SQL View?
- 9. Linq to SQL with Stored Procedures
- 10. LINQ to SQL lambda exp。 OrderBy,Case When,Where Where
- 11. .Include().Where()in Linq to Entities查询
- 12. LINQ to SQL in Visual Studio,InvalidCastException with no call stack
- 13. Linq to SQL加入和Where
- 14. DefaultIfEmpty - LINQ to SQL vs In Memory
- 15. 在LINQ to SQL中选择“IN”
- 16. LINQ to EF - 模拟SQL“IN”子句
- 17. SelectMany in Linq to entity
- 18. LINQ to SQL INSERT WHERE不在集合中
- 19. LINQ to SQL MAX在WHERE子句中
- 20. LINQ to SQL - 分组依据/ Where
- 21. LINQ查询类似于SQL WHERE x IN
- 22. SQL“WHERE IN”查询转换为LINQ
- 23. LINQ to SQL - 选择SUM与WHERE
- 24. Linq to Sql在Where子句中为空
- 25. OrderBy in LINQ to Entity
- 26. 返回@@ RowCount in LINQ to SQL INSERT
- 27. LINQ to SQL class not shown in VS
- 28. Custom Cell with protocol to check in changes in UISwitch
- 29. SQL JOIN WITH WHERE
- 30. SQL SELECT IN with like
如果您想查看描述中是否包含关键字... – 2009-06-07 00:10:15
,那么这将不起作用我想在Google提示框的行中添加一些内容。关键字不一定是完美匹配 – ak3nat0n 2009-06-07 00:50:15