Nested Select statement using LinQ

Hi All,

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

Regards,
Varsha BS

@varsha.bs
Welcome to the Forum

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

2 Likes

Hi

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’

Thanks
Varsha BS

@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

Hi,

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
System.Data.EnumerableRowCollection`1[System.String]

Expected Output: I need to get the string value

Regards
Varsha BS

@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(){
		p("ProcessFlowGroup"),
		ProcessFlowStage,
		p(“ProcessFlowStep”),
		p(“ProcessFlowShape”)
		}
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.