private void Execute(object obj) { var observer = (IObserver <TModel>)obj; try { using (var sqlConnection = KernelDatabase.CreateSqlConnection()) { sqlConnection.Open(); using (var r = new SqlCommand(SqlBuilder(), sqlConnection).ExecuteReader()) { if (r.Read()) { var model = ModelBuilder(r); if (model != null) { observer.OnNext(model); } } } observer.OnCompleted(); return; } } catch (Exception ex) { observer.OnError(ex); } }
private void Execute(object obj) { var observer = (IObserver <TModel[]>)obj; try { using (var sqlConnection = KernelDatabase.CreateSqlConnection()) { sqlConnection.Open(); using (var r = new SqlCommand(SqlBuilder(), sqlConnection).ExecuteReader()) { var ordinal = OrdinalBuilder(r); var modelBuilder = ModelBuilder; int bufferIndex = 0; TModel[] buffer = new TModel[10]; while (r.Read()) { buffer[bufferIndex++] = modelBuilder(ordinal, r); if (bufferIndex < 10) { continue; } observer.OnNext(buffer); bufferIndex = 0; buffer = new TModel[10]; } if (bufferIndex > 0) { var partialBuffer = new TModel[bufferIndex]; Array.Copy(buffer, partialBuffer, bufferIndex); observer.OnNext(partialBuffer); } } observer.OnCompleted(); } } catch (Exception ex) { observer.OnError(ex); } }