public void ExecuteScalar() { RequestContext context = new RequestContext { Scope = Scope, SqlId = "GetRecord", Request = new { Id = 2 } }; context.Setup(_smartSqlContext, _sqlBuilder); var dbSession = _sessionStore.CreateDbSession(DataSource); var result = _commandExecuter.ExecuteScalar(dbSession, context); //Assert.Equal(1, result); }
private void ParseExecuteScalarDbValue <TResult>(ExecutionContext executionContext) { var singleResult = executionContext.Result as SingleResultContext <TResult>; var dbResult = _commandExecuter.ExecuteScalar(executionContext); SetResultData(dbResult, singleResult); }
private void ParseExecuteScalarDbValue <TResult>(ExecutionContext executionContext) { var singleResult = executionContext.Result as SingleResultContext <TResult>; var dbResult = _commandExecuter.ExecuteScalar(executionContext); if (dbResult == null || dbResult == DBNull.Value) { singleResult.SetData(default(TResult)); } else { var convertType = singleResult.ResultType; convertType = Nullable.GetUnderlyingType(convertType) ?? convertType; if (convertType.IsEnum) { singleResult.SetData(Enum.ToObject(convertType, dbResult)); } else { singleResult.SetData(Convert.ChangeType(dbResult, convertType)); } } }