Need some more help with a linq query or lambda expression

T

Tony Johansson

Hello!
Below is a collection named result.
Each object in the collection is called worksheetRowParameter.

I have written a linq query but I want to have it modified a little.
In this query
var slask = from o in result
where o.Parameter.ToUpper() == paramProperty
select new {o.Value, o.WorksheetRowID};
I only wants those rows(objects) returned where I have identical rows for
parameter LS.
In my case I only want the linq query or lambda expression to return these
two rows.
114 LS 2-5003
113
123 LS 2-5003
122


So rather want to have a lambda expression but it will do with a linq quesry
as well.

Here is the collection named result
***************************
ID Parameter Value WorksheetRowID
96 LS 2-121 95
97 SLC 0
95
98 PARMG 0 95
102 ACL A1 95

105 LS 2-150 104
106 SLC 0
104
109 SLI 250
104
111 ACL A2
104

114 LS 2-5003
113
115 SLC 0
113
116 PARMG 0 113
117 ST "C7ST2C-57" 113
120 ACL A1
113

123 LS 2-5003
122
124 SLC 1
122
125 PARMG 0 122
126 ST C7ST2C-56 122
129 ACL A1
122


//Tony
 
T

Tim Jarvis

Tony said:
Hello!
Below is a collection named result.
Each object in the collection is called worksheetRowParameter.

I have written a linq query but I want to have it modified a little.
In this query
var slask = from o in result
where o.Parameter.ToUpper() == paramProperty
select new {o.Value, o.WorksheetRowID};
I only wants those rows(objects) returned where I have identical rows
for parameter LS. In my case I only want the linq query or lambda
expression to return these two rows. 114 LS
2-5003 113 123 LS 2-5003 122


So rather want to have a lambda expression but it will do with a linq
quesry as well.

Here is the collection named result
***************************
ID Parameter Value
WorksheetRowID 96 LS 2-121
95 97 SLC 0 95
98 PARMG 0
95 102 ACL A1
95

105 LS 2-150
104 106 SLC 0 104
109 SLI 250 104
111 ACL A2 104

114 LS 2-5003 113
115 SLC 0 113
116 PARMG 0
113 117 ST "C7ST2C-57"
113 120 ACL A1 113

123 LS 2-5003 122
124 SLC 1 122
125 PARMG 0
122 126 ST C7ST2C-56
122 129 ACL A1 122


//Tony

Hi Tony,

A simple group operation and sub-select should give you what you want...

var qry = from ws in
WorksheetRowParameter.GetWorkSheetRowParameters()
where ws.Parameter == "LS"
group ws by ws.value into grp
from sub in grp
where grp.Count() > 1
select sub;

Regards Tim.
 
T

Tony Johansson

Hello!

Thanks a lot!!

//Tony

Tim Jarvis said:
Hi Tony,

A simple group operation and sub-select should give you what you want...

var qry = from ws in
WorksheetRowParameter.GetWorkSheetRowParameters()
where ws.Parameter == "LS"
group ws by ws.value into grp
from sub in grp
where grp.Count() > 1
select sub;

Regards Tim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top