我有一个链接一个地方和排序依据子句两个表查询成功,但我想添加到只选择特定的列,而不是让一切恢复。
PART 1当我尝试这个我上线的OrderBy语法错误,如果我删除的排序依据行语法错误移动到哪里行。
错误3无法隐式转换类型“System.Linq.IOrderedQueryable”到“System.Linq.IQueryable”。 一个显式转换存在(是否缺少强制转换?)
IQueryable<VendorProfile> query = _db.VendorProfiles
.Include("VendorCategories")
.Include("VendorsSelected")
.Select(s => new { s.ProfileID, s.Name, s.CompanyName, s.City, s.State, s.DateCreated, s.VendorsSelected, s.VendorCategories })
.Where(x => x.VendorsSelected.Select(s => s.UserName).Contains(HttpContext.Current.User.Identity.Name))
.OrderBy(x => x.DateCreated);
if (criteria.name != string.Empty)
query = query.Where(v => v.Name.Contains(criteria.name));
if (criteria.company != string.Empty)
query = query.Where(v => v.CompanyName.Contains(criteria.company));
if (criteria.startDate != null && criteria.endDate != null)
query = query.Where(v => v.DateCreated > criteria.startDate && v.DateCreated < criteria.endDate);
if (criteria.categories != null && !criteria.categoryMatchAll)
query = query.Where(v => criteria.categories.AsQueryable().Any(cat => v.VendorCategories.Select(vendCat => vendCat.CategoryID).Contains(cat)));
if (criteria.categories != null && criteria.categoryMatchAll)
query = query.Where(v => criteria.categories.AsQueryable().All(cat => v.VendorCategories.Select(vendCat => vendCat.CategoryID).Contains(cat)));
if (criteria.minorityType != null)
query = query.Where(v => v.MinotiryOwned == criteria.minorityType);
if (criteria.diversityClass != null)
query = query.Where(v => v.DiversityClassification == criteria.diversityClass);
return query.ToList();
第2部分我也想知道如果我能提取选中的列到视图模型类,所以我厌倦了这一点,我在排序依据线上得到与上述相同的结果
错误4无法隐式转换类型“System.Linq.IOrderedQueryable”到“System.Linq.IQueryable”。 一个显式转换存在(是否缺少强制转换?)