Permalink
Browse files

Generate a SELECT for Single<T> even if EnableAutoSelect is false

  • Loading branch information...
asherber authored and pleb committed Sep 26, 2018
1 parent 2ab0f92 commit 21f7b702f0cfa5952b744c8e75b97b9fbd5b346e
Showing with 14 additions and 4 deletions.
  1. +14 −4 PetaPoco/Database.cs
View
@@ -1102,8 +1102,7 @@ public bool Exists<T>(object primaryKey)
/// </remarks>
public T Single<T>(object primaryKey)
{
return Single<T>(string.Format("WHERE {0}=@0", _provider.EscapeSqlIdentifier(PocoData.ForType(typeof(T), _defaultMapper).TableInfo.PrimaryKey)),
primaryKey);
return Single<T>(GenerateSingleByKeySql<T>(primaryKey));
}
/// <summary>
@@ -1117,8 +1116,19 @@ public T Single<T>(object primaryKey)
/// </remarks>
public T SingleOrDefault<T>(object primaryKey)
{
return SingleOrDefault<T>(
string.Format("WHERE {0}=@0", _provider.EscapeSqlIdentifier(PocoData.ForType(typeof(T), _defaultMapper).TableInfo.PrimaryKey)), primaryKey);
return SingleOrDefault<T>(GenerateSingleByKeySql<T>(primaryKey));
}
private Sql GenerateSingleByKeySql<T>(object primaryKey)
{
string pkName = _provider.EscapeSqlIdentifier(PocoData.ForType(typeof(T), _defaultMapper).TableInfo.PrimaryKey);
var sql = $"WHERE {pkName} = @0";
if (!EnableAutoSelect)
// We're going to be nice and add the SELECT anyway
sql = AutoSelectHelper.AddSelectClause<T>(_provider, sql, _defaultMapper);
return new Sql(sql, primaryKey);
}
/// <summary>

0 comments on commit 21f7b70

Please sign in to comment.