Skip to content

Commit

Permalink
Limit the Soundex SQL Query to TOP 1
Browse files Browse the repository at this point in the history
  • Loading branch information
benrick committed Apr 20, 2019
1 parent a5b4c23 commit cb8c3f9
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Dapper;
using DevChatter.DevStreams.Core.Model;
using DevChatter.DevStreams.Core.Services;
using DevChatter.DevStreams.Core.Settings;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using DevChatter.DevStreams.Core.Services;
using System.Threading.Tasks;

namespace DevChatter.DevStreams.Infra.Dapper.Services
Expand Down Expand Up @@ -45,13 +45,13 @@ public List<Channel> Find()

public async Task<Channel> GetChannelSoundex(string standardizedChannelName)
{
var sql = @"SELECT * FROM Channels WHERE SOUNDEX(Name) = SOUNDEX(@standardizedChannelName)
var sql = @"SELECT TOP 1 * FROM Channels WHERE SOUNDEX(Name) = SOUNDEX(@standardizedChannelName)
ORDER BY DIFFERENCE(Name, @standardizedChannelName) DESC";
using (System.Data.IDbConnection connection = new SqlConnection(_dbSettings.DefaultConnection))
using (IDbConnection connection = new SqlConnection(_dbSettings.DefaultConnection))
{
using (var multi = await connection.QueryMultipleAsync(sql, new { standardizedChannelName }))
{
return (await multi.ReadAsync<Channel>()).FirstOrDefault();
return (await multi.ReadAsync<Channel>()).SingleOrDefault();
}
}
}
Expand Down

0 comments on commit cb8c3f9

Please sign in to comment.