Commit 304d2b00 authored by Sam Saffron's avatar Sam Saffron

improve error message when multi mapper is misused

parent e4b05097
...@@ -804,9 +804,15 @@ IEnumerator IEnumerable.GetEnumerator() ...@@ -804,9 +804,15 @@ IEnumerator IEnumerable.GetEnumerator()
private static Func<IDataReader, T> GetDynamicDeserializer<T>(IDataRecord reader, int startBound, int length, bool returnNullIfFirstMissing) private static Func<IDataReader, T> GetDynamicDeserializer<T>(IDataRecord reader, int startBound, int length, bool returnNullIfFirstMissing)
{ {
var fieldCount = reader.FieldCount;
if (length == -1) 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 return
...@@ -1143,7 +1149,13 @@ static readonly MethodInfo ...@@ -1143,7 +1149,13 @@ static readonly MethodInfo
length = reader.FieldCount - startBound; 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>(); var names = new List<string>();
for (int i = startBound; i < startBound + length; i++) for (int i = startBound; i < startBound + length; i++)
{ {
names.Add(reader.GetName(i)); names.Add(reader.GetName(i));
......
...@@ -958,5 +958,25 @@ public void TestNullableCharInputAndOutputNull() ...@@ -958,5 +958,25 @@ public void TestNullableCharInputAndOutputNull()
obj.ValueNullable.IsEqualTo(test); 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% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment