如何从键和值对的字典中创建where条件?我有一个字典,其中包含where条件的值。
var pkkeys = new Dictionary<string, string>
{
{ "pkkey1", "value1" },
{ "pkkey2", "value2" },
{ "pkkey3", "value4" }
}
我需要创建这样的内容:
db.GetTable<SomeTable>()
.Where(t => (t.code == "pkkey1" && t.value == "value1")
|| (t.code == "pkkey2" && t.value == "value2")
|| (t.code == "pkkey3" && t.value == "value3"));
谢谢。
我尝试了下面的代码:
Expression<Func<SomeDictionary, bool>> e = (x) => false;
foreach (var dictKeyValue in dictKeyValues)
{
e.Or((t) => dictKeyValue.Code == t.Code && dictKeyValue.Value == t.Value);
}
var expe = tbl => this.dbContext.Set<SomeTable>()
.Any(e.Compile());
1条答案
按热度按时间dbf7pr2w1#
表达式第一个参数类型应为
SomeTable
。我假设是这样的表:
表情: