0

I've recently upgraded to devart 7.5 and a few functions are not working properly. Specifically, I've got a function that returns an IEnumerable:

protected IEnumerable<BudgetTotals> getTotals(decimal groupId, decimal budgetId)
{
    using (SsinpatDataContext dc = new SsinpatDataContext())
    {
         object[] ids = new object[2] { groupId, budgetId };
         string sqlStr = "..."
         var query = dc.ExecuteQuery<BudgetTotals>(sqlStr, ids);
         return query;
    }
}

To this point it all works fine, and the return variable "query" holds the correct values.
The problem is that when calling getTotals the object is not set:

...
var query = getTotals(grpId,bdgId);
foreach(BudgetTotals bt in query)
{
    ...
}

Now, when control reaches "in" in the foreach instruction an exception is thrown with the message "Object not set to an instance of an object", which is puzzling me because

a) it was working fine and

b) the object is set within the getTotals funcion.


I could work things around by changing the return value from IEnumerable to BudgetTotals[], and returning query.ToArray. I tried it and it works. The main issue here is all the other functions that return an IEnumerable.

Before overhauling the application, I'd like to understand why or what is causing this difference in behaviour from devart 6.3 to 7.5.

Thanks in advance

Freelancer
  • 9,008
  • 7
  • 42
  • 81
Ricardo Appleton
  • 679
  • 10
  • 22

1 Answers1

1

When performing the ExecuteQuery method in the 'getTotals' function, an entity reader for obtaining the data is opened for the current DataContext object (dc). After exiting the 'using' block in the "getTotals" function, the DataContext object (dc) is disposed and all its entity readers are closed. Thus, when you trying to read the data in the foreach statement, the reader is already closed, and the exception occurs (we have changed the text of the exception, now it will be more informative). JIC: In older version there could be some issues with closing entity readers.

Devart
  • 119,203
  • 23
  • 166
  • 186