开发者

How to insert row in linq query

开发者 https://www.devze.com 2023-02-12 23:19 出处:网络
This is my oracle query select 0 subcatg_cd, \'all\' subcatg_name from dual union select subcatg_cd,subcatg_name from datacontext.subcatg_mst

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 开发者_JS百科to achieve it by a single query. How can it be done?


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);
  );
0

精彩评论

暂无评论...
验证码 换一张
取 消