Skip to content

Commit d12f1aa

Browse files
DamirAinullinmgravell
authored andcommitted
Use loop variable instead of 0 (#1334)
* Use loop variable instead of 0 * Changed unit test, added additional nesting level
1 parent 7769253 commit d12f1aa

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

Dapper.Tests/AsyncTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,27 +476,30 @@ public async Task Issue346_QueryAsyncConvert()
476476
public async Task TestSupportForDynamicParametersOutputExpressionsAsync()
477477
{
478478
{
479-
var bob = new Person { Name = "bob", PersonId = 1, Address = new Address { PersonId = 2 } };
479+
var bob = new Person { Name = "bob", PersonId = 1, Address = new Address { PersonId = 2, Index = new Index() } };
480480

481481
var p = new DynamicParameters(bob);
482482
p.Output(bob, b => b.PersonId);
483483
p.Output(bob, b => b.Occupation);
484484
p.Output(bob, b => b.NumberOfLegs);
485485
p.Output(bob, b => b.Address.Name);
486486
p.Output(bob, b => b.Address.PersonId);
487+
p.Output(bob, b => b.Address.Index.Id);
487488

488489
await connection.ExecuteAsync(@"
489490
SET @Occupation = 'grillmaster'
490491
SET @PersonId = @PersonId + 1
491492
SET @NumberOfLegs = @NumberOfLegs - 1
492493
SET @AddressName = 'bobs burgers'
493-
SET @AddressPersonId = @PersonId", p).ConfigureAwait(false);
494+
SET @AddressPersonId = @PersonId
495+
SET @AddressIndexId = '01088'", p).ConfigureAwait(false);
494496

495497
Assert.Equal("grillmaster", bob.Occupation);
496498
Assert.Equal(2, bob.PersonId);
497499
Assert.Equal(1, bob.NumberOfLegs);
498500
Assert.Equal("bobs burgers", bob.Address.Name);
499501
Assert.Equal(2, bob.Address.PersonId);
502+
Assert.Equal("01088", bob.Address.Index.Id);
500503
}
501504
}
502505

Dapper.Tests/SharedTypes/Address.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace Dapper.Tests
1+
namespace Dapper.Tests
82
{
93
public class Address
104
{
115
public int AddressId { get; set; }
126
public string Name { get; set; }
137
public int PersonId { get; set; }
8+
public Index Index { get; set; }
149
}
1510
}

Dapper.Tests/SharedTypes/Index.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Dapper.Tests
2+
{
3+
public class Index
4+
{
5+
public string Id { get; set; }
6+
}
7+
}

Dapper/DynamicParameters.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,9 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
407407
il.Emit(OpCodes.Castclass, typeof(T)); // [T]
408408

409409
// Count - 1 to skip the last member access
410-
var i = 0;
411-
for (; i < (chain.Count - 1); i++)
410+
for (var i = 0; i < chain.Count - 1; i++)
412411
{
413-
var member = chain[0].Member;
412+
var member = chain[i].Member;
414413

415414
if (member is PropertyInfo)
416415
{

0 commit comments

Comments
 (0)