Search code examples
c#entity-frameworklinqlinq-to-entities

Creating LINQ query with two parameters


I am new to LINQ and I feel some difficulties to write that LINQ query.

I need to write LINQ TO ENTITY to check if table named Reviews where all rows with siteId=5 has at least one row with column named isValid that equal false if there is, I need to return false if not return true.


Solution

  • Create a Filter with SiteId

    IEnumerable<Review> FilteredReviews = Reviews.Where(x=>x.SiteId == 5)
    

    Check whether any value of IsValid is False, return accordingly

    return FilteredReviews.Any(y=>!y.IsValid) ? false : true