开发者

LINQ - How to write a query to set a variable bool True or False

开发者 https://www.devze.com 2023-02-17 17:29 出处:网络
I use asp.net 4 linq and EF4. I have this query where CmsSourcesContents is a navigational property. At he moment when I run the query the result for queryCheck is a type IQuerable.

I use asp.net 4 linq and EF4.

I have this query where CmsSourcesContents is a navigational property.

At he moment when I run the query the result for queryCheck is a type IQuerable.

I need to valuate the condition express in my Linq query but as a result I would like a Type Bool like:

bool queryCheck

Any idea how to make it? Thanks!


  var queryCheck = from cnt in context.CmsContents
      开发者_运维技巧             where cnt.ContentId == myContentIdSelected && cnt.CmsSourcesContents.Any()
                   select cnt;

This query should look for a specific cnt and check if it has any association.. and give me the result as bool.


bool queryCheck = (from cnt in context.CmsContents
                  where cnt.ContentId == myContentIdSelected && cnt.CmsSourcesContents.Any()
                  select cnt).Any();


You can use Any() again on the total query to see if there are any matches:

var queryCheck = (from cnt in context.CmsContents
               where cnt.ContentId == myContentIdSelected && cnt.CmsSourcesContents.Any()
               select cnt).Any();
0

精彩评论

暂无评论...
验证码 换一张
取 消