Anupam- / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Creating a DynamicParameters object from an anonymous type #30

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When calling a stored procedure with output parameters I have to create a 
DynamicParameters object like this:

DynamicParameters p = new DynamicParameters();
p.Add("@GameID", gameId);
p.Add("@GUIDin", sessionId);
p.Add("@StandIDin", standIDin);
p.Add("@sectionin", section);
p.Add("@zonein", zone);
p.Add("@NumberOfSeats", numberOfSeats);
p.Add("@SeatTypeIDin", seatTypes);
p.Add("@SeatCountOut", dbType: DbType.Int32, direction: 
ParameterDirection.Output);

It would be nice if most of the parameters could be initialized using an 
anonymous object like other calls using Dapper.Net, and then the 
output/ref/return parameters are added as needed:

DynamicParameters p = DynamicParameters.FromObject({ gameid, sessionId, 
standIDin, section, zone, numberOfSeats, seatTypes });
p.Add("@SeatCountOut", dbType: DbType.Int32, direction: 
ParameterDirection.Output);

Original issue reported on code.google.com by james.ne...@gmail.com on 31 May 2011 at 10:34

GoogleCodeExporter commented 9 years ago
I like this ... 

Original comment by sam.saff...@gmail.com on 1 Jun 2011 at 12:55

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 1 Jun 2011 at 8:51

GoogleCodeExporter commented 9 years ago
        public void TestExecuteCommandWithHybridParameters()
        {
            var p = new DynamicParameters(new { a = 1, b = 2 });
            p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.Output);
            connection.Execute(@"set @c = @a + @b", p);
            p.Get<int>("@c").IsEqualTo(3);
        }

Original comment by marc.gravell on 1 Jun 2011 at 11:48