Concatenating IEnumerable?

R

Ronald S. Cook

Thanks guys for all the guidance on this so far.

In the below, for _IEnumerable2, I'm just trying to hard-code one record
with "(Please Select)" for a value. I can do that easily in SQL but don't
know how here.

Any contunued help very much appreciated... Ron


Dim _IEnumerable1 As IEnumerable(Of IEnumerable) = _
From lk In dc.Lookups _
Where lk.LookupGroup = LookupGroup _
Select lk.LookupId, _
lk.LookupCode, _
lk.LookupValue

Dim _IEnumerable2 As IEnumerable(Of IEnumerable) = _
From lk In dc.Lookups _
Where lk.LookupGroup = LookupGroup _
Select lk.LookupId, _
lk.LookupCode, _
lk.LookupValue

Dim _IEnumerable3 As IEnumerable(Of IEnumerable) = _
_IEnumerable1.Concat(_IEnumerable2)
 
R

Ronald S. Cook

Thanks Nicholas.. will try. Sorry about the VB. I code in both and get
crossed up sometimes.



Nicholas Paldino said:
Ronald,

You want to do something like this:

Dim _IEnumerable2 as IEnumerable(Of IEnumerable) = _
From item in new string[]{"(Please Select)"}
Select New (LookupId = 0, LookupCode = 0, LookupValue = item)

I'm guessing what the syntax is for VB (and that IEnumerable of
IEnumerable looks odd), but the point is you can simply create an
enumerable of one element (an array of one element is enumerable) and then
select the appropriate data structure to concatenate with your previous
data structure.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Ronald S. Cook said:
Thanks guys for all the guidance on this so far.

In the below, for _IEnumerable2, I'm just trying to hard-code one record
with "(Please Select)" for a value. I can do that easily in SQL but
don't know how here.

Any contunued help very much appreciated... Ron


Dim _IEnumerable1 As IEnumerable(Of IEnumerable) = _
From lk In dc.Lookups _
Where lk.LookupGroup = LookupGroup _
Select lk.LookupId, _
lk.LookupCode, _
lk.LookupValue

Dim _IEnumerable2 As IEnumerable(Of IEnumerable) = _
From lk In dc.Lookups _
Where lk.LookupGroup = LookupGroup _
Select lk.LookupId, _
lk.LookupCode, _
lk.LookupValue

Dim _IEnumerable3 As IEnumerable(Of IEnumerable) = _
_IEnumerable1.Concat(_IEnumerable2)
 
N

Nicholas Paldino [.NET/C# MVP]

Ronald,

You want to do something like this:

Dim _IEnumerable2 as IEnumerable(Of IEnumerable) = _
From item in new string[]{"(Please Select)"}
Select New (LookupId = 0, LookupCode = 0, LookupValue = item)

I'm guessing what the syntax is for VB (and that IEnumerable of
IEnumerable looks odd), but the point is you can simply create an enumerable
of one element (an array of one element is enumerable) and then select the
appropriate data structure to concatenate with your previous data structure.
 
R

Ronald S. Cook

Nicholas.. I'm having a few twinge pains with that syntax. Could you give
it to me in C# and I'll convert? I REALLY appreciate it and promise not to
bug anymore.

Thanks!

Nicholas Paldino said:
Ronald,

You want to do something like this:

Dim _IEnumerable2 as IEnumerable(Of IEnumerable) = _
From item in new string[]{"(Please Select)"}
Select New (LookupId = 0, LookupCode = 0, LookupValue = item)

I'm guessing what the syntax is for VB (and that IEnumerable of
IEnumerable looks odd), but the point is you can simply create an
enumerable of one element (an array of one element is enumerable) and then
select the appropriate data structure to concatenate with your previous
data structure.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Ronald S. Cook said:
Thanks guys for all the guidance on this so far.

In the below, for _IEnumerable2, I'm just trying to hard-code one record
with "(Please Select)" for a value. I can do that easily in SQL but
don't know how here.

Any contunued help very much appreciated... Ron


Dim _IEnumerable1 As IEnumerable(Of IEnumerable) = _
From lk In dc.Lookups _
Where lk.LookupGroup = LookupGroup _
Select lk.LookupId, _
lk.LookupCode, _
lk.LookupValue

Dim _IEnumerable2 As IEnumerable(Of IEnumerable) = _
From lk In dc.Lookups _
Where lk.LookupGroup = LookupGroup _
Select lk.LookupId, _
lk.LookupCode, _
lk.LookupValue

Dim _IEnumerable3 As IEnumerable(Of IEnumerable) = _
_IEnumerable1.Concat(_IEnumerable2)
 
N

Nicholas Paldino [.NET/C# MVP]

Ronald,

Actually, the syntax was a bad mix of C#, now that I look at it.

In C#, I would do this:

var _IEnumerable2 =
from item in new string[] { "(Please Select)" }
select new { LookupId = 0, LookupCode = 0, LookupValue = item };

Of course, if 0 isn't applicable for the LookupId and LookupCode
properties on your anonymous type, then you need to replace them with
something that is.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ronald S. Cook said:
Nicholas.. I'm having a few twinge pains with that syntax. Could you give
it to me in C# and I'll convert? I REALLY appreciate it and promise not
to bug anymore.

Thanks!

Nicholas Paldino said:
Ronald,

You want to do something like this:

Dim _IEnumerable2 as IEnumerable(Of IEnumerable) = _
From item in new string[]{"(Please Select)"}
Select New (LookupId = 0, LookupCode = 0, LookupValue = item)

I'm guessing what the syntax is for VB (and that IEnumerable of
IEnumerable looks odd), but the point is you can simply create an
enumerable of one element (an array of one element is enumerable) and
then select the appropriate data structure to concatenate with your
previous data structure.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Ronald S. Cook said:
Thanks guys for all the guidance on this so far.

In the below, for _IEnumerable2, I'm just trying to hard-code one record
with "(Please Select)" for a value. I can do that easily in SQL but
don't know how here.

Any contunued help very much appreciated... Ron


Dim _IEnumerable1 As IEnumerable(Of IEnumerable) = _
From lk In dc.Lookups _
Where lk.LookupGroup = LookupGroup _
Select lk.LookupId, _
lk.LookupCode, _
lk.LookupValue

Dim _IEnumerable2 As IEnumerable(Of IEnumerable) = _
From lk In dc.Lookups _
Where lk.LookupGroup = LookupGroup _
Select lk.LookupId, _
lk.LookupCode, _
lk.LookupValue

Dim _IEnumerable3 As IEnumerable(Of IEnumerable) = _
_IEnumerable1.Concat(_IEnumerable2)
 
J

Jon Skeet [C# MVP]

Nicholas Paldino said:
Ronald,

Actually, the syntax was a bad mix of C#, now that I look at it.

In C#, I would do this:

var _IEnumerable2 =
from item in new string[] { "(Please Select)" }
select new { LookupId = 0, LookupCode = 0, LookupValue = item };

Of course, if 0 isn't applicable for the LookupId and LookupCode
properties on your anonymous type, then you need to replace them with
something that is.

There's no need to bring query expressions into it at all really:

var _IEnumerable2 = new[] { new { LookupId = 0,
LookupCode = 0,
LookupValue = "(Please Select)" } };
 

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