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
  • 38,833
  • 15
  • 69
  • 136
webdad3
  • 8,893
  • 30
  • 121
  • 223

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
  • 124,003
  • 15
  • 196
  • 263
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
  • 202,030
  • 26
  • 332
  • 449