471,330 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

LINQ group

responseData.Signals is a List<SignalInfo>

var signalGroups =
from signal in responseData.Signals
where signal.DisplayPath.StartsWith("AppMenu")
orderby signal.DisplayPath
group signal by signal.DisplayPath into signalGroup
select new { Title = signalGroup.Key, Signals = signalGroup };

foreach(var signalGroup in signalGroups)
foreach(SignalInfo signal in ?????????????

How do I get each SignalInfo in the group?
Thanks

Pete
Aug 23 '08 #1
4 1373
This seems very innefficient so there must be a better way of getting a list
of SignalInfo by DisplayPath.

var signalGroups =
from signal in responseData.Signals
where signal.DisplayPath.StartsWith("AppMenu")
orderby signal.DisplayPath
group signal by signal.DisplayPath into signalGroup
select new
{
Title = signalGroup.Key.Split('/')[2],
Signals = new List<SignalInfo>(from signal in responseData.Signals
where signal.DisplayPath == signalGroup.Key select signal)
};
Pete

Aug 23 '08 #2
Peter Morris wrote:
responseData.Signals is a List<SignalInfo>

var signalGroups =
from signal in responseData.Signals
where signal.DisplayPath.StartsWith("AppMenu")
orderby signal.DisplayPath
group signal by signal.DisplayPath into signalGroup
select new { Title = signalGroup.Key, Signals = signalGroup };

foreach(var signalGroup in signalGroups)
foreach(SignalInfo signal in ?????????????
Try
foreach(SignalInfo signal in signalGroup.Signals)
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 23 '08 #3
Peter Morris wrote:
responseData.Signals is a List<SignalInfo>

var signalGroups =
from signal in responseData.Signals
where signal.DisplayPath.StartsWith("AppMenu")
orderby signal.DisplayPath
group signal by signal.DisplayPath into signalGroup
select new { Title = signalGroup.Key, Signals = signalGroup };

foreach(var signalGroup in signalGroups)
foreach(SignalInfo signal in ?????????????

How do I get each SignalInfo in the group?
As Martin said in the other post, simply iterate over teh Signals property.

As you return a new type with just the key and the group, you can also do:
var signalGroups =
from signal in responseData.Signals
where signal.DisplayPath.StartsWith("AppMenu")
orderby signal.DisplayPath
group signal by signal.DisplayPath into signalGroup
select signalGroup;

You can then foreach over the query as:
foreach(IGrouping<string, Signalgroup in signalGroups)
{
// now obtain each signal in the current group
foreach(Signal s in group)
{
}
// the key is obtainable by group.Key
}

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Aug 24 '08 #4
foreach(IGrouping<string, Signalgroup in signalGroups)
foreach(Signal s in group)
That was exactly the info I needed, thanks very much!

Pete
Aug 24 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by David Veeneman | last post: by
7 posts views Thread by =?Utf-8?B?Q2hha3JhdmFydGh5?= | last post: by
4 posts views Thread by shapper | last post: by
8 posts views Thread by Alcides | last post: by
9 posts views Thread by =?Utf-8?B?cmF1bGF2aQ==?= | last post: by
3 posts views Thread by Mike P | last post: by
14 posts views Thread by thj | last post: by
21 posts views Thread by hrishy | last post: by
2 posts views Thread by shapper | last post: by
3 posts views Thread by bob laughland | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.