简体   繁体   中英

How to insert model from list into stored procedure

My program is making a query from one database and I want that query to be added to a stored procedure in another database. At first I was insert each parameter as a List, but I want to optimize the code and insert all parameters into one List. I add all select options to list:

public void GetResult(SqlCommand command)
        {

            var list = new List<Models>;

            using(var reader = command.ExecuteReader())
                while (reader.Read())
                {
                    var rows = new Models;
                    rows.Md1 = Convert.ToInt32(reader["md1"]);
                    rows.Md2 = Convert.ToInt32(reader["md2"]);

                    list.Add(rows);
                }

            using var InsertCommand = new OracleCommand();
            InsertCommand.CommandText = "PathToProcedure";

            var Param1 = new OracleParameter("param1", OracleDbType.Int32, ParameterDirecion.Input);
            Param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
            Param1.Value =
            Param2.Size = 


        }

Question: How to create a link to these rows to insert them in parameters? Thanks in advance!

SP:

create or replace package body transfer_package is

procedure getdt(param1 in t_number,
                param2 in t_number)
        is
  begin
    if param1.count > 0 then
       for i in 1 .. param1.count loop
    insert into table
          (parameter1,
           parameter2)
        values
          (param1(i),
           param2(i));
      
        end loop;
end;

The solution of my question is a Linq library...

Param1.Value = list.Select(Models => Models.Md1).ToArray();
Param2.Size = list.Select(Models => Models.Md2).ToArray();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM