How to create a nested LINQ query in C#

Hakan
Hakan used Ask the Experts™
on
Hi,

I have two linq query's and i'd like to combine them and want to create a single linq query.

I searched o net and found some examples but i didn't succeeded.

Any help would be grateful for me.



 
           var objects = Pre.ModelBase.GetExpressList((simpackcomslvLib.IScrModelBase)Pre.Spck.CurrentModel, true);

            var filteredObjects = from e in objects
                                  group e by Pre.NamedObject.GetNamedObjectModelType((simpackcomslvLib.IScrNamedObject)e);

            var filteredObjectsII = from e in objects
                                    where Pre.Expressions.ChannelType(e) == "REAL"
                                    group e by Pre.Expressions.GetChannelBaseName(e.fullName);

Open in new window


First i would like to group like below;

group e by Pre.NamedObject.GetNamedObjectModelType((simpackcomslvLib.IScrNamedObject)e);

Open in new window

and then

group element where it matchs with my statement

                            where Pre.Expressions.ChannelType(e) == "CUTF"
                                    group e by Pre.Expressions.GetCutForceChannelBaseName(e.fullName);

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Eduard GherguArchitect - Coder - Mentor

Commented:
Hi,

So, do you want that instead of filteredObjects and filteredObjectsII to have just one based on the combination of the previous ones?

Author

Commented:
Hi Eduard,

Yes exactly. I want to take in consideration the first one at second one.
Architect - Coder - Mentor
Commented:
Hi,

Can you try something like:

objects .GroupBy(e => new {
Pre.NamedObject.GetNamedObjectModelType((simpackcomslvLib.IScrNamedObject)e),
Pre.Expressions.GetChannelBaseName(e.fullName)});

The where clause is raising some question marks, but let's take it step-by-step.

Author

Commented:
I found similar solution to yours only writing is bit different. Thank you.
Eduard GherguArchitect - Coder - Mentor

Commented:
My pleasure! Let me know if you need more help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial