public override IEnumerable <T> ExecuteDeferred <T>(QueryCommand query, Func <FieldReader, T> fnProjector, MappingEntity entity, object[] paramValues) { this.LogCommand(query, paramValues); this.StartUsingConnection(); try { DbCommand cmd = this.GetCommand(query, paramValues); var reader = this.ExecuteReader(cmd); var freader = new DbFieldReader(this, reader); try { while (reader.Read()) { yield return(fnProjector(freader)); } } finally { reader.Close(); } } finally { this.StopUsingConnection(); } }
private IEnumerable <T> ExecuteBatch <T>(QueryCommand query, IEnumerable <object[]> paramSets, Func <FieldReader, T> fnProjector, MappingEntity entity) { this.LogCommand(query, null); DbCommand cmd = this.GetCommand(query, null); cmd.Prepare(); foreach (var paramValues in paramSets) { this.LogParameters(query, paramValues); this.LogMessage(""); this.SetParameterValues(query, cmd, paramValues); var reader = this.ExecuteReader(cmd); var freader = new DbFieldReader(this, reader); try { if (reader.HasRows) { reader.Read(); yield return(fnProjector(freader)); } else { yield return(default(T)); } } finally { reader.Close(); } } }
private E getEntity(DbFieldReader fieldReader) { var entity = new E(); var props = typeof(E).GetProperties(); foreach (var prop in props) { int i = fieldReader.GetOrdinal(prop.Name); entity.SetMemberValue(props[i].Name, fieldReader.Read(i, props[i].PropertyType)); } return(entity); }
private IEnumerable <E> mapList(IDataReader reader) { var fieldReader = new DbFieldReader(reader); do { while (reader.Read()) { yield return(getEntity(fieldReader)); } } while (reader.NextResult()); }
protected virtual IEnumerable <T> Project <T>(DbDataReader reader, Func <FieldReader, T> fnProjector, MappingEntity entity, bool closeReader) { var freader = new DbFieldReader(this, reader); try { while (reader.Read()) { yield return(fnProjector(freader)); } } finally { if (closeReader) { ((IDataReader)reader).Close(); } } }
private E mapScalar(IDataReader reader) { var fieldReader = new DbFieldReader(reader); return(!reader.Read() ? default(E) : fieldReader.ReadValue <E>(0)); }