Dapper Dynamic Parameters with Table Valued Parameters

后端 未结 2 1752
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-20 04:19

I was trying to create a generic method, which can read the parameters name and value from a class at Runtime and create parameter collection for Dapper query execution. Realize

2条回答
  •  后悔当初
    2021-02-20 04:50

    First create a User Defined Table type in Database

    CREATE TYPE udtt_PersonList AS TABLE 
    (
        ...
    )
    GO
    

    In your code

    var dynamicParameters = new DynamicParameters();
    dynamicParameters.Add("@PersonList", PersonList.AsTableValuedParameter("[dbo].[udtt_PersonList]"));
    dynamicParameters.Add("TestOutput", 0, Dbtype.Int32, ParameterDirection.Output);
    

提交回复
热议问题