提交 d18b53c0 编写于 作者: S Sam Saffron

improve error message when multi mapper is misused

上级 80eaa3b6
......@@ -804,9 +804,15 @@ IEnumerator IEnumerable.GetEnumerator()
private static Func<IDataReader, T> GetDynamicDeserializer<T>(IDataRecord reader, int startBound, int length, bool returnNullIfFirstMissing)
{
var fieldCount = reader.FieldCount;
if (length == -1)
{
length = reader.FieldCount - startBound;
length = fieldCount - startBound;
}
if (fieldCount <= startBound)
{
throw new ArgumentException("When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id", "splitOn");
}
return
......@@ -1143,7 +1149,13 @@ static readonly MethodInfo
length = reader.FieldCount - startBound;
}
if (reader.FieldCount <= startBound)
{
throw new ArgumentException("When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id", "splitOn");
}
var names = new List<string>();
for (int i = startBound; i < startBound + length; i++)
{
names.Add(reader.GetName(i));
......
......@@ -958,5 +958,25 @@ public void TestNullableCharInputAndOutputNull()
obj.ValueNullable.IsEqualTo(test);
}
public void TestInvalidSplitCausesNiceError()
{
try
{
connection.Query<User, User, User>("select 1 A, 2 B, 3 C", (x, y) => x);
}
catch (ArgumentException)
{
// expecting an app exception due to multi mapping being bodged
}
try
{
connection.Query<dynamic, dynamic, dynamic>("select 1 A, 2 B, 3 C", (x, y) => x);
}
catch (ArgumentException)
{
// expecting an app exception due to multi mapping being bodged
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册