Exemplo n.º 1
0
 public async Task <object> ExecuteScalarAsync(ISqlCommandDefinition command)
 {
     using (SqlCommand sqlCommand = command.GetCommand())
     {
         sqlCommand.Connection = Connection;
         return(await sqlCommand.ExecuteScalarAsync());
     }
 }
Exemplo n.º 2
0
 public object ExecuteScalar(ISqlCommandDefinition command)
 {
     using (SqlCommand sqlCommand = command.GetCommand())
     {
         sqlCommand.Connection = Connection;
         return(sqlCommand.ExecuteScalar());
     }
 }
Exemplo n.º 3
0
 public int ExecuteNonQuery(ISqlCommandDefinition command)
 {
     using (SqlCommand sqlCommand = command.GetCommand())
     {
         sqlCommand.Connection = Connection;
         return(sqlCommand.ExecuteNonQuery());
     }
 }
Exemplo n.º 4
0
 public async Task <int> ExecuteNonQueryAsync(ISqlCommandDefinition command)
 {
     using (SqlCommand sqlCommand = command.GetCommand())
     {
         sqlCommand.Connection = Connection;
         OpenConnection();
         return(await sqlCommand.ExecuteNonQueryAsync());
     }
 }
Exemplo n.º 5
0
        public static SqlCommand GetCommand(this ISqlCommandDefinition definition)
        {
            var attribute = definition.GetType()
                            .GetCustomAttributes(typeof(SqlCommandAttribute), false).FirstOrDefault() as SqlCommandAttribute;


            if (attribute != null)
            {
                SqlCommand command = new SqlCommand();
                command.CommandType = attribute.Type;
                command.CommandText = attribute.CommandText;

                command.Parameters.AddRange(definition.GetParameters().ToArray());

                return(command);
            }

            throw new ArgumentNullException("ISqlCommandDefinitionExtensions. Name of stored procedure cannot be null.");
        }
Exemplo n.º 6
0
        public static IEnumerable <SqlParameter> GetParameters(this ISqlCommandDefinition definition)
        {
            var propertiesAndAttibutes = definition.GetType()
                                         .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                         .Where(x => Attribute.IsDefined(x, typeof(SqlParameterAttribute)))
                                         .Select(x => new
            {
                property  = x,
                attribure = x.GetCustomAttributes(typeof(SqlParameterAttribute), false)
                            .FirstOrDefault() as SqlParameterAttribute
            });

            //List<SqlParameter> resultParameters = new List<SqlParameter>();

            foreach (var attr in propertiesAndAttibutes)
            {
                var propertyValue = attr.property.GetValue(definition);

                if (attr.attribure.IsRequired)
                {
                    if (propertyValue is string)
                    {
                        if (string.IsNullOrEmpty(propertyValue as string))
                        {
                            ThrowException(attr.property.Name);
                        }
                    }

                    if (propertyValue == null)
                    {
                        ThrowException(attr.property.Name);
                    }
                }

                SqlParameter sqlParameter = null;

                yield return(sqlParameter);

                //resultParameters.Add(sqlParameter);
            }

            //return resultParameters;
        }