使用List作为LINQ to SQL查询的条件 [英] Using a List as a condition for LINQ to SQL query
本文介绍了使用List作为LINQ to SQL查询的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个LINQ to SQL的查询是这样的:
I have a LINQ to SQL query that goes like this:
String NameCondition = "Test";
String EmailCondition = "test@test.com";
IQueryable<User> Users = Repository.Where(x => x.Name.Equals(NameCondition) && x.Email.Equals(EmailCondition));
但现在我有一个条件列表,我想拉用户可以从它们是否匹配任何他们(像SQL OR语句)。所以我有一个字典列表,各词典是一个姓名和电子邮件的条件:
But now I have a list of conditions where I would like to pull Users from if they match any of them (like an OR statement in SQL). So I have a list of dictionaries, and each dictionary is a condition with a name and email:
List<Dictionary<String, String>> Conditions;
我怎么能执行一个LINQ使用这些条件的SQL查询?
How can I perform a LINQ to SQL query using those conditions?
推荐答案
而不是字典使用列表与LT; KeyValuePair<字符串,字符串>>
在.NET 3.5和列表与LT元组LT;字符串,字符串>>
在.NET 4.0中
Instead of dictionary use List<KeyValuePair<string, string>>
in .NET 3.5 and List<Tuple<string, string>>
in .NET 4.0.
看到某种类似问题
这篇关于使用List作为LINQ to SQL查询的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文