You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you supply an empty collection, say you have:
var ids = new List();
connection.Query().Where(entity => ids.Contains(entity.Id));
the result is an exception, supplying no valuable information about the error.
PrepareStatement.SetupParameters method assumes there are values in the list, so it tries to remove the trailing comma, which in the case of empty list is non-existant, and raises an exception:
System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. Parameter name: startIndex at System.Text.StringBuilder.Remove(Int32 startIndex, Int32 length) at SqlFu.PrepareStatement.SetupParameters(DbCommand cmd) in e:\Projects.Net\SqlFu\src\SqlFu\PrepareStatement.cs:line 79 at ...
Perhaps the behavior should be either a more informational exception or maybe do what some other ORMs like for instance Entity Framework does, i.e the code emitted when executing the same query using EF:
SELECT
CAST(NULL AS varchar(1)) AS [C1],
CAST(NULL AS bigint) AS [C2],
.......
FROM ( SELECT 1 AS X ) AS [SingleRowTable1]
WHERE 1 = 0
Resulting in an empty result set, not an error, or another possible solution maybe not sending SELECT to the SQL server, but just giving back an empty result list.
The text was updated successfully, but these errors were encountered:
When you supply an empty collection, say you have:
var ids = new List();
connection.Query().Where(entity => ids.Contains(entity.Id));
the result is an exception, supplying no valuable information about the error.
PrepareStatement.SetupParameters method assumes there are values in the list, so it tries to remove the trailing comma, which in the case of empty list is non-existant, and raises an exception:
System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. Parameter name: startIndex at System.Text.StringBuilder.Remove(Int32 startIndex, Int32 length) at SqlFu.PrepareStatement.SetupParameters(DbCommand cmd) in e:\Projects.Net\SqlFu\src\SqlFu\PrepareStatement.cs:line 79 at ...
Perhaps the behavior should be either a more informational exception or maybe do what some other ORMs like for instance Entity Framework does, i.e the code emitted when executing the same query using EF:
SELECT
CAST(NULL AS varchar(1)) AS [C1],
CAST(NULL AS bigint) AS [C2],
.......
FROM ( SELECT 1 AS X ) AS [SingleRowTable1]
WHERE 1 = 0
Resulting in an empty result set, not an error, or another possible solution maybe not sending SELECT to the SQL server, but just giving back an empty result list.
The text was updated successfully, but these errors were encountered: