mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-16 21:03:18 +08:00
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.
This commit is contained in:
@@ -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}<T> only supports an entity with a single [Key] or [ExplicitKey] property");
|
||||
throw new DataException($"{method}<T> 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}<T> only supports an entity with a [Key] or an [ExplicitKey] property");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user