Commit a0ba65a4 authored by johandanforth's avatar johandanforth

Fixed missing check for explicit key in Contrib GetaAync()

parent 7f22bff5
......@@ -32,17 +32,18 @@ public static partial class SqlMapperExtensions
if (!GetQueries.TryGetValue(type.TypeHandle, out sql))
{
var keys = KeyPropertiesCache(type);
if (keys.Count() > 1)
throw new DataException("Get<T> only supports an entity with a single [Key] property");
if (!keys.Any())
throw new DataException("Get<T> only supports en entity with a [Key] property");
var explicitKeys = ExplicitKeyPropertiesCache(type);
if (keys.Count() > 1 || explicitKeys.Count() > 1)
throw new DataException("Get<T> only supports an entity with a single [Key] or [ExplicitKey] property");
if (!keys.Any() && !explicitKeys.Any())
throw new DataException("Get<T> only supports an entity with a [Key] or an [ExplicitKey] property");
var onlyKey = keys.First();
var key = keys.Any() ? keys.First() : explicitKeys.First();
var name = GetTableName(type);
// TODO: query information schema and only select fields that are both in information schema and underlying class / interface
sql = "select * from " + name + " where " + onlyKey.Name + " = @id";
sql = "select * from " + name + " where " + key.Name + " = @id";
GetQueries[type.TypeHandle] = sql;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment