Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

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

 

 

 

 

 

 

 

 

 

 

 

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)

{

    setProductIDs.Add(Convert.ToInt32(sID));

}

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

foreach (string sMonth in arrParameter_SetMonths)

{

    setMonths.Add(Convert.ToDateTime(sMonth));

}

//</ 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);

 

Mobile

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de