Skip to content

Bug?: SqlException: Incorrect syntax near ')' #463

@nunomcardoso

Description

@nunomcardoso

Greetings.

I came across this error/bug (?) a few times already:
When I call Query() in BaseRepository<TEntity, TDbConnection>:

var collection = new List<int>(); // Count = 0
return Query(e=> collection.Contains(e.Attribute));

If the collection is empty it throws this exceptions:

SqlException: Incorrect syntax near ')'.
Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, bool breakConnection, Action<Action> wrapCloseInAction)

The SQL code (grabbed from SQL Server Profiler) being generated is:

SELECT [Attribute], [OtherAttribute] FROM [Table1] WHERE ([Attribute] IN ()) ;

Had this issue in March and took this screenshot back then: https://i.imgur.com/ekmP9RS.png

Is there any solution other than this:

var collection = new List<int>(); // Count = 0
if(!collection.Any()) 
    return Enumerable.Empty<T>();
return Query(e=> collection.Contains(e.attribute)) 

Thanks!

Metadata

Metadata

Assignees

Labels

deployedFeature or bug is deployed at the current releasefixedThe bug, issue, incident has been fixed.questionFurther information is requestedunder assessmentThe feature request is under assessment

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions