将IQueryable附加到IQueryable

时间:2018-01-26 20:52:22

标签: c# linq iqueryable

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

我需要在q

结尾处的q1中有数据

1 个答案:

答案 0 :(得分:-1)

试试这个:

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

但是,您也可以在一个查询中合并两个查询:

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