"An unhandled exception of type 'System.StackOverflowException' occurred in SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll" is everything from the detail of the exception, there is no more information about what is happening. I'm running from the code-behind of an asp.net 2.0 web application in debug mode.
In preparation for this post I've realized that the problem is not necessarily related to the the ISNULL function but that I am trying to determine the field to sort on based on a string. I have done this in the past with success however when I try to apply to the ISNULL code to the field I am receiving the stack overflow message.
Here is a working code snippet. ApplicationStatus is the column I'm sorting on, it is possible that some students do not have a record in the StudentStatus table.
StudentCollection students = new StudentCollection();
RelationCollection relations = new RelationCollection(StudentEntity.Relations.StudentStatusEntityUsingStudentId, JoinHint.Left);
IEntityField isNullField = StudentStatusFields.ApplicationStatus.SetExpression(
new DbFunctionCall("ISNULL", new object[] { StudentStatusFields.ApplicationStatus, "zzz" }));
SortClause isNullSortClause = new SortClause(isNullField, SortOperator.Ascending);
isNullSortClause.EmitAliasForExpressionAggregateField = false;
SortExpression sorter = new SortExpression(isNullSortClause);
students.GetMulti(null, 0, sorter, relations);
Here is the code snippet I'm trying to get working. The field to sort on is passed in as a string (hard-coded to "ApplicationStatus" for now).
StudentCollection students = new StudentCollection();
RelationCollection relations = new RelationCollection(StudentEntity.Relations.StudentStatusEntityUsingStudentId, JoinHint.Left);
IEntityField field = EntityFieldFactory.Create((StudentStatusFieldIndex)Enum.Parse(typeof(StudentStatusFieldIndex), "ApplicationStatus"));
IEntityField isNullField = field.SetExpression(
new DbFunctionCall("ISNULL", new object[] { field, "zzz" }));
SortClause isNullSortClause = new SortClause(isNullField, SortOperator.Ascending);
isNullSortClause.EmitAliasForExpressionAggregateField = false;
SortExpression sorter = new SortExpression(isNullSortClause);
students.GetMulti(null, 0, sorter, relations);