0
var q = _context.a
                .Include(x => x.status)
                .Include(x => x.type)
                .Where(x => x.status == 20);

var q1 = _context.a
                 .Include(x => x.status)
                 .Include(x => x.type)
                 .Where(x => x.status == 40);

I need to have data in q1 at the end of q

Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62
spartans bmk
  • 371
  • 1
  • 5
  • 9
  • 1
    Check this: [`Queryable.Concat`](https://msdn.microsoft.com/en-us/library/bb351755(v=vs.110).aspx). Previously answered [here](https://stackoverflow.com/a/4003842/6352706). – Ben Harris Jan 26 '18 at 20:57
  • @BenHarris I have tried var q2 = q.concat(q1) which returns me nothing – spartans bmk Jan 26 '18 at 21:08

1 Answers1

-1

Try this:

var q = _context.a
                .Include(x => x.status)
                .Include(x => x.type)
                .Where(x => x.status == 20).AsQueryable();//ATTENTION AsQueryable()

var q1 = _context.a
                 .Include(x => x.status)
                 .Include(x => x.type)
                 .Where(x => x.status == 40).AsQueryable();//ATTENTION AsQueryable()

q = q.Concat(q1);

However you can just combine your two queries in one query too:

var q = _context.a
                .Include(x => x.status)
                .Include(x => x.type)
                .Where(x => x.status == 20 || x.status == 40)
                .OrderBy(x=>x.status);
Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62
  • the reason I am trying to concat is I need the records with status 40 to be at the end of the table. Values I have in status are 10,20,30,40,50,60,70 but I need to get the records with status 40 to the end of the table. I already tried q = q.Concat(q1); but its giving me Null – spartans bmk Jan 29 '18 at 18:24
  • @spartansbmk why you do not just add a flag column and sort the result based on this flag? for example set 1 for 40 and set 0 for the remaining and then just sort based on this flag, without using concat! – Vahid Farahmandian Jan 29 '18 at 22:05
  • @spartansbmk for q=q.Concat(q1) you will need to add AsQueryable() to the both q and q1, as stated in the provided code – Vahid Farahmandian Jan 29 '18 at 22:06