Beispiel #1
0
 public SqlDataReader ExecuteReader()
 {
     using (QueryTime.Measure(this))
     {
         return(this.sqlCommand.ExecuteReader());
     }
 }
Beispiel #2
0
 public int ExecuteNonQuery()
 {
     using (QueryTime.Measure(this))
     {
         return(this.sqlCommand.ExecuteNonQuery());
     }
 }
Beispiel #3
0
 public SqlDataReader ExecuteReader(CommandBehavior behavior)
 {
     using (QueryTime.Measure(this))
     {
         return(this.sqlCommand.ExecuteReader(behavior));
     }
 }
Beispiel #4
0
        public T SelectSingleValue <T>()
        {
            if (SqlCommand.Connection == null)
            {
                throw new InvalidOperationException("SqlCommand.Connection is not set.");
            }

            using (QueryTime.Measure(this))
            {
                var value = sqlCommand.ExecuteScalar();
                if (value == null)
                {
                    return(default(T));
                }

                // Special case for Id<> and LongId<>
                var targetConvertType = typeof(T);
                if (IdTypeExtension.IsIdType(targetConvertType))
                {
                    var constructor = targetConvertType.GetConstructor(new[] { typeof(int) });
                    if (constructor == null)
                    {
                        throw new InvalidCastException("The Id<> type has no constructor taking int as a parameter.");
                    }

                    return((T)constructor.Invoke(new object[] { Convert.ToInt32(value) }));
                }
                else if (LongIdTypeExtension.IsLongIdType(targetConvertType))
                {
                    var constructor = targetConvertType.GetConstructor(new[] { typeof(long) });
                    if (constructor == null)
                    {
                        throw new InvalidCastException("The LongId<> type has no constructor taking long as a parameter.");
                    }

                    return((T)constructor.Invoke(new object[] { Convert.ToInt64(value) }));
                }

                // Just execute the query, don't close the connection
                return(DataRowExtensionsCustom.Get <T>(value));
            }
        }