0

I have this LINQ2SQL statement:

var value = from o in DataContext.Table
            where o.Active == "Yes"
            orderby o.Name
            select o;

I'd like to append a new Name to this list (i.e. "Select Option 4");

I'm not sure how I can accomplish this (if I can)?

value could have:

Option 1
Option 2
Option 3

I also want to be able to add:

Select Option 4
Yuriy Galanter
  • 36,794
  • 12
  • 65
  • 122
webdad3
  • 8,758
  • 29
  • 117
  • 212

2 Answers2

1
var value = (from o in DataContext.Table
            where o.Active == "Yes"
            orderby o.Name
            select o).AsEnumerable()
                     .Concat(new [] { new TableObject() });

Of course, it will not change your database content at all.

MarcinJuraszek
  • 121,297
  • 15
  • 183
  • 252
0

You can use Concat to concat another sequence, and then just put the one item you want into its own sequence:

value = value.Concat(new[]{"Select a different Option"});

If this is something you do often enough you can create an extension method to handle it for you:

public static IEnumerable<T> Concat<T>(this IEnumerable<T> source, T item)
{
    return source.Concat(new[] { item });
}
Servy
  • 197,813
  • 25
  • 319
  • 428