From b961089eff365e48a071108e283345216b85b2ef Mon Sep 17 00:00:00 2001 From: Wixely Date: Sat, 9 Feb 2019 12:19:33 +0000 Subject: [PATCH] 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. --- Dapper.Contrib/SqlMapperExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dapper.Contrib/SqlMapperExtensions.cs b/Dapper.Contrib/SqlMapperExtensions.cs index 7aac1004..f8a8f216 100644 --- a/Dapper.Contrib/SqlMapperExtensions.cs +++ b/Dapper.Contrib/SqlMapperExtensions.cs @@ -153,7 +153,7 @@ namespace Dapper.Contrib.Extensions var explicitKeys = ExplicitKeyPropertiesCache(type); var keyCount = keys.Count + explicitKeys.Count; if (keyCount > 1) - throw new DataException($"{method} only supports an entity with a single [Key] or [ExplicitKey] property"); + throw new DataException($"{method} only supports an entity with a single [Key] or [ExplicitKey] property. [Key] Count: {keys.Count}, [ExplicitKey] Count: {explicitKeys.Count}"); if (keyCount == 0) throw new DataException($"{method} only supports an entity with a [Key] or an [ExplicitKey] property");