Nested Select statement using LinQ

Hi All,

Can someone give me an example on how to write nested select statement using LinQ.

Varsha BS
Welcome to the Forum

Please Share more Details with us. Can you Post some Sample Data and expected Output description. Thanks



I need to write below query using LinQ.

Select TOP 5 ProcessFlowTable.ProcessFlowGroup,(Select Stages.StageName from Stages where Stages.ProcessFlowGroup = ‘1’) as ProcessFlowStage,ProcessFlowTable.ProcessFlowStep,ProcessFlowTable.ProcessFlowShape,ProcessFlowTable.ProcessFlowShape as ShapeStyleSheet,ProcessFlowTable.ProcessFlowStep, ProcessFlowTable.ProcessFlowLabel,“+strStepSelected+” as StepSelected from ProcessFlowTable where ProcessFlowTable.ProcessFlowGroup = ‘1’

Varsha BS
Kindly note: LINQ is not SQL
However can you please give some details on requirements. It looks like a databse query

1 Like


Yes this is a Database query and I need to convert to LinQ query. I have done almost and only thing which is not working is the select statement which is inside the Select.
So I need a help on this.

Below is the LinQ that I have done for the above SQL.

(From p In In_dtProcessFlowTable.AsEnumerable()
Where Convert.ToString(p(“ProcessFlowGroup”))=“1”
Select dtTempTable.LoadDataRow(New Object() {p.Field(Of Double)(“ProcessFlowGroup”),(From s In In_dtStages Where Convert.ToString(s(“ProcessFlowGroup”))=“1” Select s.Field(Of String)(“StageName”)),p.Field(Of String)(“ProcessFlowStep”),p.Field(Of String)(“ProcessFlowShape”),p.Field(Of String)(“ProcessFlowShape”),p.Field(Of String)(“ProcessFlowStep”),p.Field(Of String)(“ProcessFlowLabel”)},False)).Take(5).CopyToDataTable

Actual Output: I am getting below output for nested select

Expected Output: I need to get the string value

Varsha BS

some details are hidden to me. However to start have a look on the rearranged LINQ

(From p In In_dtProcessFlowTable.AsEnumerable()
Where p(“ProcessFlowGroup”).toString.Equals(“1”)
Let ProcessFlowStage = In_dtStages.AsEnumerable.Where(Function (ds) ds("ProcessFlowGroup").toString.Equals("1"))
Let ra = New Object(){
Select dtTempTable.Rows.Add(ra)).Take(5).CopyToDataTable

Respect the line breaks and just complete the column list from the object Array. Maybe you get it running or we go into a next iteration.

Kindly note: LINQ is different from SQL
Help you can find here:

and sure here in the forum we are here for helping you

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.