1

うまくいきました-私の解決策を以下に投稿しましたが、より良い方法があるかどうか知りたいです

皆さんこんにちは

データベースに (移行後に) 新しく作成されたドメイン オブジェクトのドメイン イベントを作成しようとしています。

内部子オブジェクトを持たないオブジェクトの場合、スクリプト コンポーネントを使用することで問題なく動作しました。問題は、子行を取得してイベント オブジェクトに情報を追加する方法にあります。

元。顧客 -> 顧客の所在地。

スクリプト コンポーネントで変換としてイベントを作成し (ドメイン イベント モジュールへの参照があります)、イベントに関するシリアル化された情報を列の値として送信するように作成しています。入力行は現在、親オブジェクトのデータを提供しています。

お知らせ下さい。

よろしく、

ザ マール

編集 1

現在処理を行っていることを追加したいと思います

public override void Input0_ProcessInputRow(Input0Buffer Row)

この関数でデータリーダーを作成するようなものを探しています

データ行をループ -> 子オブジェクトを作成し、それを親コレクションに追加

まだ Google と PreExecute と ProcessInput で何かを調べているようです。ここに画像の説明を入力

4

1 に答える 1

1

これが私の解決策です。私は SSIS の初心者なので、これが最善の解決策ではないかもしれません。

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    IDTSConnectionManager100 connectionManager;
    SqlCommand cmd = null;
    SqlConnection conn = null;
    SqlDataReader reader = null;


    public override void AcquireConnections(object Transaction)
    {

        try
        {
            connectionManager = this.Connections.ScriptConnectionManager;
            conn = connectionManager.AcquireConnection(Transaction) as SqlConnection;

            // Hard to debug failure-  better off logging info to file
            //using (StreamWriter outfile =
            //    new StreamWriter(@"f:\Migration.txt"))
            //{
            //    outfile.Write(conn.ToString());
            //    outfile.Write(conn.State.ToString());
            //}
        }
        catch (Exception ex)
        {
            //using (StreamWriter outfile =
            //    new StreamWriter(@"f:\Migration.txt"))
            //{
            //    outfile.Write(" EEEEEEEEEEEEEEEEEEEE"+ ex.ToString());
            //}
        }




    }


    public override void PreExecute()
    {
        base.PreExecute();

        cmd = new SqlCommand("SELECT [CustomerLocation fields] FROM customerlocationView where custid=@CustId", conn);
        cmd.Parameters.Add("CustId", SqlDbType.UniqueIdentifier);

    }

    public override void PostExecute()
    {
        base.PostExecute();
        /*
          Add your code here for postprocessing or remove if not needed
          You can set read/write variables here, for example:
          Variables.MyIntVar = 100
        */
    }

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        Collection<CustomerLocation> locations = new Collection<CustomerLocation>();
        cmd.Parameters["CustId"].Value = Row.id;

        // Any error always  saw that reader reamians open on connection
        if (reader != null)
        {
            if (!reader.IsClosed)
            {
                reader.Close();
            }
        }

        reader = cmd.ExecuteReader();

        if (reader != null)
        {
            while (reader.Read())
            {
                // Get Child Details
                var customerLocation = new CustomerLocation(....,...,...,);
                customerLocation.CustId = Row.id;
                locations.Add(customerLocation);
            }



        }






        var newCustomerCreated = new NewCustomerCreated(Row.id,,...,...,locations);

        var serializedEvent = JsonConvert.SerializeObject(newCustomerCreated, Formatting.Indented,
                                                                    new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, ReferenceLoopHandling = ReferenceLoopHandling.Ignore });

        Row.SerializedEvent = serializedEvent;
        Row.EventId = newCustomerCreated.EventId;
        ...
        ...
        ...
        ....
        ..
        .
        Row.Version = 1;



       // using (StreamWriter outfile =
        //       new StreamWriter(@"f:\Migration.txt", true))
       // {
       //     if (reader != null)
         //   {
         //       outfile.WriteLine(reader.HasRows);
            //outfile.WriteLine(serializedEvent);
          //  }
           // else
          //  {
          //      outfile.Write("reader is Null");
          //  }
        //}
        reader.Close();
    }



    public override void ReleaseConnections()
    {
        base.ReleaseConnections();
        connectionManager.ReleaseConnection(conn);
    }
}

注意すべきことの 1 つは、接続を作成する別の方法として、connectionManager から接続文字列を取得し、それを使用して OLEDB 接続を作成することです。

于 2011-09-13T14:32:44.217 に答える