Ulhas Tuscano
Ulhas Tuscano

Reputation: 5620

How to insert row in linq query

This is my oracle query

select 0 subcatg_cd, 'all' subcatg_name from dual
union
select subcatg_cd,subcatg_name from datacontext.subcatg_mst
order by 1

I want to insert 0 & all at index 0 of the result of second query using linq. I want to achieve it by a single query. How can it be done?

Upvotes: 0

Views: 380

Answers (1)

Andrey
Andrey

Reputation: 60085

I think best option will be to query rest of the data (second sentence) and then join them on client side.

So:

class Subcat
{
    public int subcatg_cd;
    public string subcatg_name;
}

then

new Subcat[] { new Subcat() { subcatg_cd = 1, subcatg_name = "All" } }
  .Concat(
      datacontext.subcatg_mst
         .Select(s => new Subcat() { subcatg_cd = s.subcatg_cd, subcatg_name = s.subcatg_name })
         .OrderBy(s => s.subcatg);
  );

Upvotes: 3

Related Questions