		public static IOrderedQueryable<OrdersHost> ApplyWmsOrderingSequencerRetrievalTime(this IQueryable<OrdersHost> entity,
			IWcsDbContext db)
		{
			var query = entity
				.GroupJoin(
					db.OrdersHost
						.GroupBy(xx => xx.IdOrderWmsHead)
						.Select(g => new
						{
							IdOrderWmsHead = g.Key,
							SequencerRetrievalTime = g.Min(y => y.SequencerRetrievalTime)
						}),
					o => o.IdOrderWmsHead,
					m => m.IdOrderWmsHead,
					(o, m) => new { o, m }
				)
				.SelectMany(x => x.m.DefaultIfEmpty(), (x, m) => new { x.o, m })
				.OrderByDescending(x => x.o.IsStolen)
				.ThenByDescending(x => x.o.IsDirectPicking)
				.ThenByDescending(x => x.m.SequencerRetrievalTime != null)
				.ThenBy(x => x.m.SequencerRetrievalTime)
				.ThenBy(x => x.o.Created)
				.Select(x => x.o);
			return (IOrderedQueryable<OrdersHost>) query;
		}