我知道还有其他一些关于此例外的帖子,但没有一个对我有帮助。
3个解决方案中的每一个都在我的本地计算机上工作,但不在Live-System / On the Server上。
随着PackageViewModels数量的增加,First Solution退出了工作。 - 实施第二解决方案。用户添加了两个项目,第二个解决方案也退出了工作 - 实现了第三个,从未在服务器上工作。 :d
编辑: - 更多信息......函数GetTemplateTypes(),GetTemplateCategories()和GetPackages()返回通过ADO.net原始SQL从SQL Server 2008查询的模型列表。这些函数总是返回查询数据和theres永远不会有任何异常抛出。
public ActionResult Package_Read([DataSourceRequest] DataSourceRequest request)
{
try
{
var templateTypes = DBRepository.GetTemplateTypes();
var templateCategories = DBRepository.GetTemplateCategories();
var templatePackages = DBRepository.GetPackages();
// Third Solution, never worked
List<PackageViewModel> packageViewModels = new List<PackageViewModel>();
foreach (var templatePackage in templatePackages)
{
PackageViewModel packageViewModel = new PackageViewModel();
packageViewModel.val1= templatePackage.val1;
packageViewModel.val2= templatePackage.val2;
packageViewModel.ID = templatePackage.ID;
packageViewModel.Type =
(from t in templateTypes where t.ID == templatePackage.ID select t).First();
packageViewModel.Category = (from t in templateCategories
where t.Category_ID == templatePackage.Category_ID
select t).First();
packageViewModels.Add(packageViewModel);
}
// Second Soltuion - Worked for an amount up to 14 packageViewModels
var packageViewModels = templatePackages.Select(p => new PackageViewModel
{
VPackage_ID = p.VPackage_ID,
VType = (from t in templateTypes where t.ID == p.VType_ID select t).Single(),
VCategory = (from t in templateCategories
where t.VCategory_ID == p.VCategory_ID select t).Single(),
val1 = p.val1,
val2 = p.val2
}).ToList();
// First Solution - Worked till a specific number of PackageViewModels ( about 12)
IEnumerable<PackageViewModel> packages = DBRepository.GetPackages()
.Select(p => new PackageViewModel
{
VPackage_ID = p.VPackage_ID,
VType = DBRepository.GetTemplateType(p.VType_ID),
VCategory = DBRepository.GetTemplateCategory(p.VCategory_ID),
val1 = p.val1,
val2 = p.val2,
});
var jsonResult = Json(packageViewModels.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
catch (Exception ex)
{
Util.logger.Error(ex.Message);
return new JsonResult();
}
}
我绝对不知道如何处理这个问题。
提前致谢!
答案 0 :(得分:1)
ERROR 2016-09-12 16:09:28,695 890063ms Util Package_Read
At least one object must implement IComparable
ERROR 2016-09-12 16:09:28,696 890064ms Util Package_Read - mscorlib
ERROR 2016-09-12 16:09:28,697 890065ms Util Package_Read
at System.Collections.Comparer.Compare(Object a, Object b)
at System.Collections.Generic.ObjectComparer`1.Compare(T x, T y)
at System.Linq.EnumerableSorter`2.CompareKeys(Int32 index1, Int32 index2)
at System.Linq.EnumerableSorter`2.CompareKeys(Int32 index1, Int32 index2)
at System.Linq.EnumerableSorter`1.QuickSort(Int32[] map, Int32 left, Int32 right)
at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
at System.Linq.Enumerable.<SkipIterator>d__30`1.MoveNext()
at Kendo.Mvc.Extensions.QueryableExtensions.Execute[TModel,TResult](IQueryable source, Func`2 selector)
at Kendo.Mvc.Extensions.QueryableExtensions.CreateDataSourceResult[TModel,TResult](IQueryable queryable, DataSourceRequest request, ModelStateDictionary modelState, Func`2 selector)
at Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable queryable, DataSourceRequest request, ModelStateDictionary modelState)
at Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable enumerable, DataSourceRequest request)
at Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IEnumerable enumerable, DataSourceRequest request)
错误被抛出
var jsonResult = Json(packageViewModels.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
找到一个解决方案,在视图中更改了kendo UI Grid的排序。仍然不明白为什么不同的解决方案正在发挥作用。现在看来一切正常。