Skip to content

Commit f499062

Browse files
committed
Use FirstOrDefault method instead of Map in Belgrade benchmark.
`FirstOrDefault` is probably meant to be used here, as there is selected and returned a single record by ID. Also changing the benchmark description, as "ExecuteReader" looks to be an obsolete name of the method that was used before refactoring.
1 parent 6468583 commit f499062

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

benchmarks/Dapper.Tests.Performance/Benchmarks.Belgrade.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,28 @@ public void Setup()
1818
_mapper = new QueryMapper(ConnectionString);
1919
}
2020

21-
[Benchmark(Description = "ExecuteReader")]
22-
public async Task<Post> ExecuteReader()
21+
[Benchmark(Description = "FirstOrDefault")]
22+
public Task<Post> FirstOrDefault()
2323
{
2424
Step();
25-
var post = new Post();
26-
await _mapper.Sql("SELECT TOP 1 * FROM Posts WHERE Id = @Id").Param("Id", i).Map(
27-
reader =>
28-
{
29-
post.Id = reader.GetInt32(0);
30-
post.Text = reader.GetString(1);
31-
post.CreationDate = reader.GetDateTime(2);
32-
post.LastChangeDate = reader.GetDateTime(3);
25+
return _mapper.Sql("SELECT TOP 1 * FROM Posts WHERE Id = @Id").Param("Id", i).FirstOrDefault(
26+
reader => new Post
27+
{
28+
Id = reader.GetInt32(0),
29+
Text = reader.GetString(1),
30+
CreationDate = reader.GetDateTime(2),
31+
LastChangeDate = reader.GetDateTime(3),
3332

34-
post.Counter1 = reader.IsDBNull(4) ? null : (int?)reader.GetInt32(4);
35-
post.Counter2 = reader.IsDBNull(5) ? null : (int?)reader.GetInt32(5);
36-
post.Counter3 = reader.IsDBNull(6) ? null : (int?)reader.GetInt32(6);
37-
post.Counter4 = reader.IsDBNull(7) ? null : (int?)reader.GetInt32(7);
38-
post.Counter5 = reader.IsDBNull(8) ? null : (int?)reader.GetInt32(8);
39-
post.Counter6 = reader.IsDBNull(9) ? null : (int?)reader.GetInt32(9);
40-
post.Counter7 = reader.IsDBNull(10) ? null : (int?)reader.GetInt32(10);
41-
post.Counter8 = reader.IsDBNull(11) ? null : (int?)reader.GetInt32(11);
42-
post.Counter9 = reader.IsDBNull(12) ? null : (int?)reader.GetInt32(12);
43-
});
44-
return post;
33+
Counter1 = reader.IsDBNull(4) ? null : (int?)reader.GetInt32(4),
34+
Counter2 = reader.IsDBNull(5) ? null : (int?)reader.GetInt32(5),
35+
Counter3 = reader.IsDBNull(6) ? null : (int?)reader.GetInt32(6),
36+
Counter4 = reader.IsDBNull(7) ? null : (int?)reader.GetInt32(7),
37+
Counter5 = reader.IsDBNull(8) ? null : (int?)reader.GetInt32(8),
38+
Counter6 = reader.IsDBNull(9) ? null : (int?)reader.GetInt32(9),
39+
Counter7 = reader.IsDBNull(10) ? null : (int?)reader.GetInt32(10),
40+
Counter8 = reader.IsDBNull(11) ? null : (int?)reader.GetInt32(11),
41+
Counter9 = reader.IsDBNull(12) ? null : (int?)reader.GetInt32(12),
42+
});
4543
}
4644
}
4745
}

0 commit comments

Comments
 (0)