chriseldredge / Lucene.Net.Linq

LINQ provider to run native queries on a Lucene.Net index
Other
151 stars 65 forks source link

Count() returning exception #50

Closed i8beef closed 10 years ago

i8beef commented 10 years ago

Whenever I call .Count() on a LuceneQueryable I get the following exception:

[InvalidOperationException: The operands for operator 'Equal' do not match the parameters of method 'op_Equality'.] System.Linq.Expressions.Expression.GetMethodBasedBinaryOperator(ExpressionType binaryType, Expression left, Expression right, MethodInfo method, Boolean liftToNull) +4339023 System.Linq.Expressions.Expression.Equal(Expression left, Expression right, Boolean liftToNull, MethodInfo method) +6153784 System.Linq.Expressions.Expression.MakeBinary(ExpressionType binaryType, Expression left, Expression right, Boolean liftToNull, MethodInfo method, LambdaExpression conversion) +94 Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression) +261 Remotion.Linq.Clauses.WhereClause.TransformExpressions(Func2 transformation) +41 Lucene.Net.Linq.Transformation.QueryModelTransformer.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index) +332 Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection1 bodyClauses, QueryModel queryModel) +284 Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel) +73 Lucene.Net.Linq.LuceneQueryExecutorBase1.PrepareQuery(QueryModel queryModel) +109 Lucene.Net.Linq.LuceneQueryExecutorBase1.ExecuteScalar(QueryModel queryModel) +45 Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo.ExecuteScalarQueryModel(QueryModel queryModel, IQueryExecutor executor) +79 Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo.ExecuteQueryModel(QueryModel queryModel, IQueryExecutor executor) +207 Remotion.Linq.QueryProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) +35 System.Linq.Queryable.Count(IQueryable`1 source) +298

i8beef commented 10 years ago

Split this up into multiple messages to make it easier to follow.

In this case, my wrapper (_hazardSearchService.Query()) just returns a provider.AsQueryable(ClassMap().ToDocumentMapper()). I couldn't find any documentation on how you were supposed to use the fluent mappings, but this seemed to fit.

The actual entity type that is being queried (HazardBase in this case) is an POCO which overrides the equality operators for use in an ORM (NHibernate). My thought was this might be where I'm getting this, but I don't understand your workflow enough to troubleshoot.

i8beef commented 10 years ago

Actually it appears to happen whenever the query is actually analyzed by Remotion.Linq? A .ToList() will trigger the same error.

chriseldredge commented 10 years ago

Can you provide examples of your operator overloads? This looks like it could be a problem in Remotion.Linq, but I'm not sure.

i8beef commented 10 years ago

Actually, I think the equality operators are fine... What it appears to be is that I am querying based on a contained object, e.g.:

var superset = _hazardSearchService.Query().Where(x => x.RecordStatus.Name == "OPEN");

Below is the mapping I am trying to use:

    public HazardBaseMap(Version version) : base(version)
    {
        Property(x => x.Id);
        Property(x => x.Description).Stored().WithTermVector.Yes().BoostBy(5);
        Property(x => x.RecordStatus.Name).ToField("RecordStatus").Stored().WithTermVector.No();
        Property(x => x.CenterOfRecord.Name).ToField("CenterOfRecord").Stored().WithTermVector.Yes();
        Property(x => x.Number).Stored().WithTermVector.Yes();
        Property(x => x.IncidentDate);
        Property(x => x.CreatedDate);
    }
chriseldredge commented 10 years ago

Lucene.Net.Linq doesn't handle nested properties like x.RecordStatus.Name. You could expose a wrapper property like RecordStatusName that maps this on your class.

i8beef commented 10 years ago

Was afraid you were going to say that... thanks.