我必须在 C# 中使用谓词使用 where in 子句过滤数据(获取具有在列表中传递的 ID 的数据)

问题描述 投票:0回答:1
supplierIdsList.Add(246); 
supplierIdsList.Add(249); 
supplierIdsList.Add(1551260);

var flagPredicate = new List<Expression<Func<FlagEntity, bool>>>();

flagPredicate.Add(x => x.Deleted == "0" && x.Flag.IsDeleted == "0" && x.Flag.Status == "1" );
flagPredicate.Add(x => (x.EntityType == 5 && x.EntityId.Contains("1551260")) || (x.EntityType == 10 && x.EntityId.Contains(supplierIdsList)));

var flagData1 = GetAsync(flagPredicate).ToList();

这是我的代码,它在

supplierIdsList
传递中出错,而不是获取数据

我想从具有

entity_id
IN
supplierIdsList

的数据库中获取数据
c# entity-framework predicate
1个回答
0
投票
flagPredicate.Add(x => (x.EntityType == 5 && x.EntityId.Contains("1551260")) || (x.EntityType == 10 && supplierIdsList.Contains(int.Parse(x.EntityId))));

它应该以这种方式工作。

© www.soinside.com 2019 - 2024. All rights reserved.