I have been using IQuery.UniqueResult<T> to execute a named query (stored procedure) that inserts rows into a table and returns the new row. Every execution it would mysteriously insert two new rows. I narrowed it down to the implementation of AbstractqueryImpl.UniqueResult<T>:
Code:
public T UniqueResult<T>()
{
object result = UniqueResult();
if (result == null && typeof(T).IsValueType)
{
throw new InvalidCastException("UniqueResult<T>() cannot cast null result to value type. Call UniqueResult<T?>() instead");
}
else
{
return (T)UniqueResult();
}
}
It first calls UniqueResult() to get a resulting value. After checking to see if the result is of the type requested it again calls UniqueResult() to return it's value. This was causing the query to be issued twice.
I'm not sure if this is an issue or if it is working as intended. It definitely caused me a headache. Perhaps I am using the wrong method to issue a stored procedure that inserts data?
Should this:
Code:
return (T)UniqueResult();
be changed to this:
Code:
return (T)result;
?
-Adam