none
How to add an item to Linq to SQL query RRS feed

  • Question

  • I would like to add an item to linq to sql query (not add a record to db!).

    for example:

    IEnumerable query = from s in dataContext.table
                                    select new
                                    {
                                        ID = s.ID,
                                        P = s.Program
                                    };

    I would like to add an item (record) to my query. How?
    I use this query for ComboBox!

    Thanks for help in advance!

    Simon
    Friday, June 26, 2009 12:40 PM

Answers

  • Call ToList() on the result. Then you'll be able to mutate the output:


    var query = (from s in dataContext.table
                                    select new
                                    {
                                        ID = s.ID,
                                        P = s.Program
                                    }).ToList();

    query.Add (new { ID = 123, P = "foo" } );


    Joe


    Write LINQ queries interactively - www.linqpad.net
    • Marked as answer by si124 Friday, June 26, 2009 1:15 PM
    Friday, June 26, 2009 12:46 PM
    Answerer