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

I am using asp.net 4 linq and EF4.

I have this query where CmsSourcesContents is a navigation property.

The moment I run the query, the result for queryCheck is the IQuerable type.

I need to evaluate the expression of an expression in my Linq query, but as a result I would like a Bool Type like:

bool queryCheck 

Any idea how to do this? 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 connection .. and give me the result as a bool.

+4
source share
2 answers
 bool queryCheck = (from cnt in context.CmsContents where cnt.ContentId == myContentIdSelected && cnt.CmsSourcesContents.Any() select cnt).Any(); 
+5
source

You can use Any() again in the general query to see if there are matches:

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

Source: https://habr.com/ru/post/1344170/


All Articles