实体框架联盟和分页

时间:2016-11-25 17:11:54

标签: sql asp.net-mvc entity-framework linq

我通过运行两个查询并使用union子句连接它来获取结果查询。我必须使用分页,但我需要结果作为插入行。我不想再订购了。但是当我使用分页时,我必须使用order by子句。如何以自然顺序获得结果。

var prodFullTextQuery = _db.Products
                            .Where(x => !x.IsDeleted
                                    && x.ProdStatusValue == (int)ProdStatus.Active
                                    && (x.ProdName.Contains(searchText)
                                        || x.Keywords.Contains(searchText)
                                        || x.ManufacturerCode.StartsWith(searchText)
                            ));

IQueryable<Product> prodQuery;

prodQuery = _db.Products.Where(x => !x.IsDeleted
                                    && x.ProdStatusValue == (int)ProdStatus.Active
                                    && x.VariantMainProdId == x.ProdId);

foreach (var s in searchText.Split(' '))
{
    var temp = s;
    prodQuery = prodQuery.Where(x => x.Keywords.Contains(temp));
}                           


prodFullTextQuery = prodFullTextQuery.Union(prodQuery)

//i need here by the order in which rows are inserted                           
var results= prodFullTextQuery
                .OrderBy(x=>x.OrderId) //i don't want this
                .Skip(prodCountPerPage * pageNumber)
                .Take(prodCountPerPage)
                .ToList()

0 个答案:

没有答案