Beispiel #1
0
        public T Scalar <T>(string sql, object param, int?timeout = null)
        {
            var cmd = SqlFactory.CreateCommand(_conn, sql, param, CommandType.Text);

            cmd.Transaction = _trans;
            using (cmd)
            {
                var obj  = cmd.ExecuteScalar();
                var obj1 = TypeMap.ConvertToType(obj, typeof(T));
                return(obj1 == null ? default(T) : (T)obj1);
            }
        }
Beispiel #2
0
        private object GetReaderValue(IDataReader reader, int index)
        {
            if (reader.FieldCount <= index)
            {
                return(TypeMap.ConvertToType(null, typeof(object)));
            }

            var type = reader.GetFieldType(index);
            var obj  = reader.GetValue(index);

            return(TypeMap.ConvertToType(obj, type));
        }
Beispiel #3
0
        public T Scalar <T>(string sql, object param, int?timeout = null)
        {
            var conn = CreateConnection(true);

            try
            {
                var cmd = SqlFactory.CreateCommand(conn, sql, param, CommandType.Text);
                using (cmd)
                {
                    OpenConnection(conn);
                    var obj  = cmd.ExecuteScalar();
                    var obj1 = TypeMap.ConvertToType(obj, typeof(T));
                    return(obj1 == null ? default(T) : (T)obj1);
                }
            }
            finally
            {
                CloseConnection(conn);
            }
        }
Beispiel #4
0
        private T DeserializerClass <T>(IDataReader reader)
        {
            var dict = DeserializerDictionary <Dictionary <string, object> >(reader);

            var entity = Activator.CreateInstance <T>();

            entity.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public)
            .ToList().ForEach(op =>
            {
                if (dict.Any(x => x.Key.ToUpper().Equals(op.Name.ToUpper())))
                {
                    op.SetValue(
                        entity,
                        TypeMap.ConvertToType(dict.First(x => x.Key.ToUpper().Equals(op.Name.ToUpper())).Value, op.PropertyType),
                        null
                        );
                }
            });

            return(entity);
        }