Skip to content

Commit b961089

Browse files
WixelyNickCraver
authored andcommitted
Improve Exception message (#1154)
In cases where the object has a property named ID, the property will automatically be assigned as [Key], even if [Computed] is added manually in an attempt to override it. This can cause confusion, this exception will be thrown despite the code looking fine and there only being one [ExplicitKey] defined. I've added this extra line of information to help diagnosis.
1 parent 5927c66 commit b961089

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Dapper.Contrib/SqlMapperExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private static PropertyInfo GetSingleKey<T>(string method)
153153
var explicitKeys = ExplicitKeyPropertiesCache(type);
154154
var keyCount = keys.Count + explicitKeys.Count;
155155
if (keyCount > 1)
156-
throw new DataException($"{method}<T> only supports an entity with a single [Key] or [ExplicitKey] property");
156+
throw new DataException($"{method}<T> only supports an entity with a single [Key] or [ExplicitKey] property. [Key] Count: {keys.Count}, [ExplicitKey] Count: {explicitKeys.Count}");
157157
if (keyCount == 0)
158158
throw new DataException($"{method}<T> only supports an entity with a [Key] or an [ExplicitKey] property");
159159

0 commit comments

Comments
 (0)