0

Getting error while executing the below code Error:Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

public ICollection<Employee> GetEmployeeDataList(RetriveEmployeeDetailsOnEntity request)
{
    ICollection<Employee> returnValue = null;

    SectionManagerHr.Execute(() =>
    {
        using (var tx = _Dao.Session.BeginTransaction())
        {
            var query = getEmployeeDataQuery(request);

            returnValue = query.List();
            tx.Commit();
        }
    });

    return returnValue;
}

private IQueryOver<Employee> getEmployeeDataQuery(RetriveEmployeeDetailsOnEntity request)
{
    Employee employee = null;
    EmployeeData employeeData = null;
    EmployeePayrollDefinition employeePayrollDefinition = null;

    var query = _Dao.Session
         .QueryOver(() => employee)
         .JoinAlias(() => employee.EmployeeDataList, () => employeeData, JoinType.LeftOuterJoin)
         .JoinAlias(() => employee.EmployeePayrollDefinitionList, () => employeePayrollDefinition, JoinType.LeftOuterJoin)
         .TransformUsing(Transformers.DistinctRootEntity)
        .Where(() => employee.CompanyEntityId == request.EntityId);
    return query;
}
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • 1
    The error you mention " Error:Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack" is something that the DEBUGGER produces, and it's an error that happens when Visual Studio tries to show the the value of some property in debug mode. It probably has nothing to do with the real error at run time. – Oskar Berggren Sep 02 '15 at 13:34

1 Answers1

0

I would say, that the exception you get is just wrapping the real problem:

NHibernate.QueryException : Cannot simultaneously fetch multiple bags.

Because I would expect that these are collections:

 employee.EmployeeDataList  // expect it is a IList<EmployeeData>
 employee.EmployeePayrollDefinitionList // IList<EmployeePayrollDefinition>

and they both cannot be used in ONE Query.

I would suggest to use some kind of batch fetching:

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335