Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collections' contains method causes exception when nullable's value passed as argument #330

Closed
andrei-traktatovich opened this issue Sep 21, 2016 · 0 comments
Milestone

Comments

@andrei-traktatovich
Copy link

if Poco class has a nullable member, e.g.
public class SomePocoClass
{
int? Number get;set;}
}
and the following query is run against it
var somelist = new List { 1,2,3,4};
var items = database.Query().Where(x => somlist.Contains(x.Number.Value)).ToList();
the .Value property of Nullable is treated as if Number were a nested class in SomePocoClass. This causes the following exception:
Did you forget to include the property eg. Include(x => x.Number)
Stack:
at NPoco.Expressions.SqlExpression1.VisitMemberAccess(MemberExpression m) at NPoco.Expressions.SqlExpression1.Visit(Expression exp)
at NPoco.Expressions.SqlExpression1.VisitExpressionList(ReadOnlyCollection1 original)
at NPoco.Expressions.SqlExpression1.VisitStaticArrayMethodCall(MethodCallExpression m) at NPoco.Expressions.SqlExpression1.VisitMethodCall(MethodCallExpression m)
at NPoco.Expressions.SqlExpression1.Visit(Expression exp) at NPoco.Expressions.SqlExpression1.VisitLambda(LambdaExpression lambda)
at NPoco.Expressions.SqlExpression1.Visit(Expression exp) at NPoco.Expressions.SqlExpression1.ProcessInternalExpression()
at NPoco.Expressions.SqlExpression1.And(Expression1 predicate)
at NPoco.Expressions.SqlExpression1.Where(Expression1 predicate)
at NPoco.Linq.QueryProvider1.Where(Expression1 whereExpression)

I.e. NPoco does not transate .Contains into SQL where Number in (...), because it stumbles at the .Value property of the nullable parameter of .Contains
If somelist is declared as List<int?> everything works just fine.

@schotime schotime added this to the 3.4.4 milestone Sep 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants