In my repository code, I am getting a disposable instance of Database. I am then using this to return an IAsyncEnumable
of my object type. The problem I'm running into is that the database object is being disposed before the enumeration happens at all -- so the connection is closed from under it. What is the pattern to solve this? (if it matters -- which it shouldn't -- this is NPoco).
I am editing the problem to say that it is specific to IAsyncEnumerable such that the awaited row-by-row fetch is more appropriate in this context, as opposed to assembling an entire List of results and returning that at once.
public IAsyncEnumerable<T_AccountViewProperty> RetrieveManyAsync(AccountViewId input)
{
var database = GetDatabase();
return database.Query<T_AccountViewProperty>()
.Where(x => x.AccountViewId == (int)input)
.ToEnumerableAsync()
.DisposeWhenCompleted(database); // <-- is this a thing?
}