public void TestTVPWithAdditionalParams() { try { connection.Execute("CREATE TYPE int_list_type AS TABLE (n int NOT NULL PRIMARY KEY)"); connection.Execute("CREATE PROC get_values @ints int_list_type READONLY, @stringParam varchar(20), @dateParam datetime AS select i.*, @stringParam as stringParam, @dateParam as dateParam from @ints i"); var dynamicParameters = new DynamicParameterWithIntTVP(new int[] { 1, 2, 3 }); dynamicParameters.AddDynamicParams(new { stringParam = "stringParam", dateParam = new DateTime(2012, 1, 1) }); var results = connection.Query("get_values", dynamicParameters, commandType: CommandType.StoredProcedure).ToList(); results.Count.IsEqualTo(3); for (int i = 0; i < results.Count; i++) { var result = results[i]; Assert.IsEqualTo(i + 1, result.n); Assert.IsEqualTo("stringParam", result.stringParam); Assert.IsEqualTo(new DateTime(2012, 1, 1), result.dateParam); } } finally { try { connection.Execute("DROP PROC get_values"); } finally { connection.Execute("DROP TYPE int_list_type"); } } }
public void TestTVPWithAdditionalParams() { try { connection.Execute("CREATE TYPE int_list_type AS TABLE (n int NOT NULL PRIMARY KEY)"); connection.Execute("CREATE PROC get_values @ints int_list_type READONLY, @stringParam varchar(20), @dateParam datetime AS select i.*, @stringParam as stringParam, @dateParam as dateParam from @ints i"); var dynamicParameters = new DynamicParameterWithIntTVP(new int[] { 1, 2, 3 }); dynamicParameters.AddDynamicParams(new { stringParam = "stringParam", dateParam = new DateTime(2012, 1, 1) }); var results = connection.Query("get_values", dynamicParameters, commandType: CommandType.StoredProcedure).ToList(); results.Count.IsEqualTo(3); for (int i = 0; i < results.Count; i++) { var result = results[i]; Assert.IsEqualTo(i + 1, result.n); Assert.IsEqualTo("stringParam", result.stringParam); Assert.IsEqualTo(new DateTime(2012, 1, 1), result.dateParam); } } finally { try { connection.Execute("DROP PROC get_values"); } finally { connection.Execute("DROP TYPE int_list_type"); } } }