Example #1
0
 public DataCommand FillParameters(Query qry, IEnumerable<ParameterValue> paramValues)
 {
     foreach (var p in _command.Parameters.Cast<DbParameter>())
     {
         var pv = paramValues.FirstOrDefault(x => x.Name == p.ParameterName);
         if (pv != null)
             p.Value = pv.Value == null ? DBNull.Value : pv.Value;
         else
         {
             var defaultValue = qry.Parameters.First(x => x.Name == p.ParameterName).DefaultValue;
             if (defaultValue != null) p.Value = defaultValue;
         }
     }
     return this;
 }
Example #2
0
        public DataCommand Build(Query q)
        {
            var cmd = _factory.CreateCommand();
            cmd.CommandText = q.Text;
            cmd.CommandType = q.Type;

            foreach (var p in q.Parameters)
            {
                var param = cmd.CreateParameter();
                param.ParameterName = p.Name;
                param.Direction = p.Direction;
                SetDbType(param, p.Type);
                if (p.Size.HasValue) param.Size = p.Size.Value;
                var iDbDataParam = param as IDbDataParameter;
                if (iDbDataParam != null)
                {
                    if (p.Precision.HasValue) iDbDataParam.Precision = p.Precision.Value;
                    if (p.Scale.HasValue) iDbDataParam.Scale = p.Scale.Value;
                }
                cmd.Parameters.Add(param);
            }

            return new DataCommand(cmd);
        }
Example #3
0
 public DataCommand Build(Query qry)
 {
     if (builder == null) builder = new QueryBuilder(_dataConfig.Factory);
     return builder.Build(qry);
 }
Example #4
0
 public void Execute(Query qry, IEnumerable<ParameterValue> paramValue)
 {
     var cmd = _handler.Build(qry);
     Transaction = cmd.OpenConnection(this);
     cmd.FillParameters(qry, paramValue).ExecuteNonQuery();
     //treat the return values of the function!!!
 }
Example #5
0
 public object LoadObject(Query qry, IEnumerable<ParameterValue> paramValue)
 {
     var cmd = _handler.Build(qry);
     Transaction = cmd.OpenConnection(this);
     var reader = cmd.FillParameters(qry, paramValue).ExecuteReader();
     if (reader.Read())
     {
     }
     reader.Close();
     //treat the return values of the function!!!
     return null;
 }