Return int on a select using Dapper.

1

I need to return the idCity. If it does not find in one table, it is mandatory in the other. Return is null.

My Query

public const string sql = @"DECLARE @retorno AS INT = 0;
                            SELECT @retorno = id 
                            FROM tabCidade1
                            WHERE nomeCidade = 'Curitiba'

                            SELECT @retorno = id
                            FROM tabCidade2
                            WHERE nomeCidade = 'Curitiba'

                            SELECT @retorno;";

Code in C #

using (var connection = My.ConnectionFactory())
{
    connection.Open();

    int idCidade = connection.Query<int>(sql);       
}
    
asked by anonymous 30.11.2017 / 13:56

1 answer

0

Missing .Single () on your command

using (var connection = My.ConnectionFactory())
{
    connection.Open();

    int idCidade = connection.Query<int>(sql).Single();       
}

    
03.12.2017 / 13:01