-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathExecuteQueryProcedureStatement.cs
More file actions
67 lines (58 loc) · 2.38 KB
/
Copy pathExecuteQueryProcedureStatement.cs
File metadata and controls
67 lines (58 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SqlRepo.Abstractions;
using SqlRepo.SqlServer.Abstractions;
namespace SqlRepo.SqlServer
{
public class ExecuteQueryProcedureStatement<TEntity> : ExecuteProcedureStatement<IEnumerable<TEntity>>,
IExecuteQueryProcedureStatement<TEntity>
where TEntity: class, new()
{
private readonly IEntityMapper entityMapper;
public ExecuteQueryProcedureStatement(IStatementExecutor commandExecutor, IEntityMapper entityMapper)
: base(commandExecutor)
{
this.entityMapper = entityMapper;
}
public override IEnumerable<TEntity> Go()
{
if(string.IsNullOrWhiteSpace(this.ProcedureName))
{
throw new MissingProcedureNameException();
}
var procedureName = $"[{this.SchemaName}].[{this.ProcedureName}]";
using(var reader = this.ParameterDefinitions.Any()
? this.StatementExecutor.ExecuteStoredProcedure(procedureName,
this.ParameterDefinitions.ToArray())
: this.StatementExecutor.ExecuteStoredProcedure(procedureName))
{
return this.entityMapper.Map<TEntity>(reader);
}
;
}
public override async Task<IEnumerable<TEntity>> GoAsync()
{
if(string.IsNullOrWhiteSpace(this.ProcedureName))
{
throw new MissingProcedureNameException();
}
var procedureName = $"[{this.SchemaName}].[{this.ProcedureName}]";
using(var reader = this.ParameterDefinitions.Any()
? await this.StatementExecutor.ExecuteStoredProcedureAsync(procedureName,
this.ParameterDefinitions.ToArray())
: await this.StatementExecutor.ExecuteStoredProcedureAsync(procedureName))
{
return this.entityMapper.Map<TEntity>(reader);
}
;
}
public IExecuteQueryProcedureStatement<TEntity> UsingMappingProfile(
IEntityMappingProfile mappingProfile)
{
this.entityMapper.UseMappingProfile(mappingProfile);
return this;
}
}
}