I recently develop a handler for DataTable for MVC
, but I am having an issue. For some reason, when I am sorting my data to be retrieved from my MySql server, it gives me duplicates of the same people every time.
I figured if this was just odd that it would be random people or everyone, but this is not the case. I narrowed the problem to this piece of my code, but I have tried several things and I cannot understand why.
I have done a straight forward sort
and it worked just fine. I can only conclude that this something to do with my machine because I do not remember having this issue on another one. If anyone can help me out and understand why it is doing this, I would be grateful.
Expression<Func<T, object>> sortExpression = null;
if(lambda.Lambda == null)
{
var param = Expression.Parameter(typeof(T), "item");
sortExpression = Expression.Lambda<Func<T, object>>(
Expression.Property(param, lambda.ColumnName), param);
//Expression.Convert(Expression.Property(param, lambda.ColumnName), typeof(object)), param);
}
if(order == null) {
if(lambda.IsDescending)
{
if (sortExpression != null)
order = results.OrderByDescending(sortExpression.Compile());
else
order = results.OrderByDescending(lambda.Lambda);
}
else
{
if (sortExpression != null)
order = results.OrderBy(sortExpression.Compile());
else
order = results.OrderBy(lambda.Lambda);
}
}
else
{
if (lambda.IsDescending)
{
if (sortExpression != null)
order = order.ThenByDescending(sortExpression.Compile());
else
order = order.ThenByDescending(lambda.Lambda);
}
else
{
if (sortExpression != null)
order = order.ThenBy(sortExpression.Compile());
else
order = order.ThenBy(lambda.Lambda);
}
}
}