有人可以建议我为 linq 中的参考表项添加条件的解决方案吗?我有一个名为 TourPackage 的主表,其中包括public class TourPackage{ public int TourID { get; set; } public string TourName { get; set; } public List<IncludedItems> IncludedItems { get; set; }}每个旅游套餐都包含一些选定的项目参考,如public class IncludedItems { public int TourID { get; set; } public int IncludedID { get; set; } public Included Included { get; set; }}所有包含的项目都应参考包含表以供查找参考public class Included { public int IncludedID { get; set; } public string IncludedValue { get; set; }}现在我有一组 IncludedID,如 [1,2,3],是否可以根据 IncludedID 过滤 TourPackage。
2 回答
暮色呼如
TA贡献1853条经验 获得超9个赞
您可以使用以下代码
我有example包含 ID 的样本数组(即),我们检查当前的 Id(即ele.Included.IncludedID)是否存在于 id 的数组中。
listex.Where(x => x.IncludedItems.Any(ele => example.Contains(ele.Included.IncludedID))).ToList();
样本:-
int[] example = new int[3];
example[0] = 123;
example[1] = 456;
example[2] = 789;
List<TourPackage> listex = new List<TourPackage>();
List<TourPackage> filterList = listex.Where(x => x.IncludedItems.Any(ele => example.Contains(ele.Included.IncludedID))).ToList();
- 2 回答
- 0 关注
- 168 浏览
添加回答
举报
0/150
提交
取消