Subquery in Where Clause of LINQ statement c# entity-framework linq linq-to-entities


So, in order to have a sub-query in the where clause of this LINQ query, I tried to follow the this example.

var innerquery =
    from app in context.applications
    select new { app.app_id };

IEnumerable<postDatedCheque> _entityList = context.postDatedCheques
    .Where(e => innerquery.Contains(e.appSancAdvice.application.app_id));

The goal was to choose the entries from the table applications that have the columns app_id.

However, I am encountering the following issues with the where clause:

  1. Assign "System." Func doesn't accept a single argument.
  2. Because string is not a delegate type, it cannot be converted from a lambda expression to that type.
  3. The best extension method overload, "System.Linq.ParallelEnumerable.Contains(System.Linq.ParallelQuery, TSource)," has some erroneous parameters and "System.Linq.IQueryable" lacks a definition for "Contains."
  4. Cannot convert from "System.Linq.IQueryable" to "System.Linq.ParallelQuery" in the instance argument

What am I incorrectly coding?

5/23/2017 10:31:25 AM

Accepted Answer

4/16/2015 6:57:39 AM

Popular Answer

Then what?

IEnumerable<postDatedCheque> _entityList = context.postDatedCheques.Where(
     e => context.applications.Any(
          x => e.appSancAdvice.application.app_id == x.app_id));

Additionally, make the first statement an expression function if you wish to use two statements.

Expression<Func<string, bool>> innerQuery = 
          x => context.applications.Any(y => y.app_id == x);

IEnumerable<postDatedCheque _entityList = 
    x => innerQuery(x.appSancAdvice.application.app_id));

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow