LINQ - 如何编写查询来设置变量bool True或False

Gib*_*boK 4 c# linq linq-to-entities entity-framework

我使用asp.net 4 linq和EF4.

我有这个查询,其中CmsSourcesContents是一个导航属性.

在我运行查询时,queryCheck的结果是类型IQuerable.

我需要在我的Linq查询中评估条件表达,但结果我想要一个Type Bool,如:

bool queryCheck
Run Code Online (Sandbox Code Playgroud)

知道怎么做吗?谢谢!


  var queryCheck = from cnt in context.CmsContents
                   where cnt.ContentId == myContentIdSelected && cnt.CmsSourcesContents.Any()
                   select cnt;
Run Code Online (Sandbox Code Playgroud)

此查询应查找特定的cnt并检查它是否有任何关联..并将结果作为bool给我.

msa*_*het 5

bool queryCheck = (from cnt in context.CmsContents
                  where cnt.ContentId == myContentIdSelected && cnt.CmsSourcesContents.Any()
                  select cnt).Any();
Run Code Online (Sandbox Code Playgroud)