public T ReadSingle(DbDataReader reader, ObjectsChangeTracker changeTracker) { T result = reader.Read() ? MapUsingState(reader, reader) : default(T); if (changeTracker != null) { changeTracker.RegisterObject(result); } return(result); }
public IEnumerable <T> ReadCollection(DbDataReader reader, ObjectsChangeTracker changeTracker) { while (reader.Read()) { T result = MapUsingState(reader, reader); if (changeTracker != null) { changeTracker.RegisterObject(result); } yield return(result); } reader.Close(); }
public static T ToObject <T>(this DbDataReader reader, string readerName, string[] excludeFields, ObjectsChangeTracker changeTracker) { ///这里将数据库表对应的字段串在一起赋值给readerName变量,方便后面判断非数据库字段 if (string.IsNullOrEmpty(readerName)) { var mappingKeyBuilder = new StringBuilder(); for (int i = 0; i < reader.FieldCount; ++i) { mappingKeyBuilder.Append(reader.GetName(i)); mappingKeyBuilder.Append('$'); } readerName = mappingKeyBuilder.ToString().ToLower(); } T result = new DataReaderToObjectMapper <T>(readerName, null, excludeFields).MapUsingState(reader, reader); if (changeTracker != null) { changeTracker.RegisterObject(result); } return(result); }