小编Act*_*tic的帖子

C#Linq - 获取非空集合的对象

我有:

private Dictionary<int, ?olor[]> colorSet = new Dictionary<int, ?olor[]>()
{
   {1, new ?olor[2] {?olor.Red, ?olor.Green}},
   {2, new ?olor[2] {?olor.Yellow, ?olor.Blue}},
   ...
};

public class Graph
{
   public ?olor ?olor { get; set; }
   public ICollection<Point> Points { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

1)我如何List<Graph>从数据库中获取Points非空的?

List<Graph> graphs = context.Graphs.Where(g => g.Points.Count > 0).ToList()
Run Code Online (Sandbox Code Playgroud)

2)如何执行?

List<Graph> graphs = context.Graphs.Where(g => colorSet[1].Contains(g.Color)).ToList()
Run Code Online (Sandbox Code Playgroud)

例外是:

LINQ to Entities 无法识别方法'...'方法,并且此方法无法转换为商店表达式.

c# linq

9
推荐指数
1
解决办法
253
查看次数

标签 统计

c# ×1

linq ×1