Ejemplo n.º 1
0
    public void AddParameters(IDbCommand command)
    {
        var sqlCommand = (SqlCommand)command;

        sqlCommand.CommandType = CommandType.StoredProcedure;

        List <Microsoft.SqlServer.Server.SqlDataRecord> number_list =
            new List <Microsoft.SqlServer.Server.SqlDataRecord>();

        // Create an SqlMetaData object that describes our table type.
        Microsoft.SqlServer.Server.SqlMetaData[] tvp_definition =
        {
            new Microsoft.SqlServer.Server.SqlMetaData("n",  SqlDbType.Int),
            new Microsoft.SqlServer.Server.SqlMetaData("n2", SqlDbType.Int)
        };

        foreach (int n in tuples)
        {
            // Create a new record, using the metadata array above.
            Microsoft.SqlServer.Server.SqlDataRecord rec =
                new Microsoft.SqlServer.Server.SqlDataRecord(tvp_definition);
            rec.SetInt32(0, n.Item1);
            rec.SetInt32(1, n.Item2);
            number_list.Add(rec);          // Add it to the list.
        }

        // Add the table parameter.
        var p = sqlCommand.Parameters.Add("ints", SqlDbType.Structured);

        p.Direction = ParameterDirection.Input;
        p.TypeName  = "int_tuple_list_type";
        p.Value     = number_list;
    }
Ejemplo n.º 2
0
        public void AddParameter(IDbCommand command, string name)
        {
            var sqlCommand = (SqlCommand)command;

            sqlCommand.CommandType = CommandType.StoredProcedure;

            var ids = new List <Microsoft.SqlServer.Server.SqlDataRecord>();

            // Create an SqlMetaData object that describes our table type.
            Microsoft.SqlServer.Server.SqlMetaData[] tvpDefinition = { new Microsoft.SqlServer.Server.SqlMetaData("Id", SqlDbType.Int) };

            foreach (var id in Ids)
            {
                // Create a new record, using the metadata array above.
                var rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvpDefinition);
                rec.SetInt32(0, id); // Set the value.
                ids.Add(rec);        // Add it to the list.
            }

            // Add the table parameter.
            var p = sqlCommand.Parameters.Add(name, SqlDbType.Structured);

            p.Direction = ParameterDirection.Input;
            p.TypeName  = "Ids";
            p.Value     = ids;
        }
Ejemplo n.º 3
0
        public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
        {
            var sqlCommand = (SqlCommand)command;

            sqlCommand.CommandType = CommandType.StoredProcedure;

            var numberList = new List <Microsoft.SqlServer.Server.SqlDataRecord>();

            // Create an SqlMetaData object that describes our table type.
            Microsoft.SqlServer.Server.SqlMetaData[] tvpDefinition =
            {
                new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.Int)
            };

            foreach (var number in numbers)
            {
                // Create a new record, using the metadata array above.
                var rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvpDefinition);
                rec.SetInt32(0, number); // Set the value.
                numberList.Add(rec);     // Add it to the list.
            }

            // Add the table parameter.
            var p = sqlCommand.Parameters.Add(parameterName, SqlDbType.Structured);

            p.Direction = ParameterDirection.Input;
            p.TypeName  = "[LAF].[IntegerListTableType]";
            p.Value     = numberList;
        }
Ejemplo n.º 4
0
            public new void AddParameters(IDbCommand command, Dapper.SqlMapper.Identity identity)
            {
                base.AddParameters(command, identity);

                var sqlCommand = (SqlCommand)command;
                sqlCommand.CommandType = CommandType.StoredProcedure;

                List<Microsoft.SqlServer.Server.SqlDataRecord> number_list = new List<Microsoft.SqlServer.Server.SqlDataRecord>();

                // Create an SqlMetaData object that describes our table type.
                Microsoft.SqlServer.Server.SqlMetaData[] tvp_definition = { new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.Int) };

                foreach (int n in numbers)
                {
                    // Create a new record, using the metadata array above.
                    Microsoft.SqlServer.Server.SqlDataRecord rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvp_definition);
                    rec.SetInt32(0, n);    // Set the value.
                    number_list.Add(rec);      // Add it to the list.
                }

                // Add the table parameter.
                var p = sqlCommand.Parameters.Add("ints", SqlDbType.Structured);
                p.Direction = ParameterDirection.Input;
                p.TypeName = "int_list_type";
                p.Value = number_list;

            }