The following LINQ statement filters data in a Linq query with sub-sets.

The filter is referred to subqueries with . ANY(value in Subdata).

Technically, this solution also corresponds to a ForEach query, in which an OR filter is set up in the WHERE (Filter=A OR Filter=B).



//*add OR into WHERE Statement AS ANY

data = data.Where(q => subData.Any(subData.ID=> q.ID==subData.IDProduct));


SQL Syntax, LINQ, Subquery OR Condition

LINQ: Creating Multiple OR Subqueries in a WHERE Condition











LINQ: Creating Multiple OR Subqueries in a WHERE Condition


string sSQL_Result = "";


//< get items >

String[] arrParameter_SetIDs = param_SetItems.setids.Split(";");

String[] arrParameter_SetMonths = param_SetItems.setmonths.Split(";");

int intSetDay = Convert.ToInt32( param_SetItems.setday) ;

//</ get items >


//< convert >

List<int> setProductIDs = new List<int>();

foreach (string sID in arrParameter_SetIDs)




List<DateTime> setMonths = new List<DateTime>();

foreach (string sMonth in arrParameter_SetMonths)




//</ convert >


//--< connect_db >--

var query_ProductDates = (from tblProductDates in _dbContext.tbl_ProductDates

select tblProductDates);

//--</ connect_db >--


//-< SubQuery.SelectIDs >-

//*add OR into WHERE Statement

query_ProductDates = query_ProductDates.Where(

    q => setProductIDs.Any(IDProduct=> IDProduct==q.IDProduct)



//-</ SubQuery.SelectIDs >-



sSQL_Result = query_ProductDates.ToQueryString(); //SQL string

sSQL_Result = sSQL_Result + "\n";

foreach(var r in query_ProductDates)


    sSQL_Result = sSQL_Result + "\n" + r.IDProduct;




return Ok(sSQL_Result);


Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel