chriseldredge / Lucene.Net.Linq

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

Can't create query terms with enum types #41

Closed cherrydev closed 10 years ago

cherrydev commented 11 years ago

Any time I use a enum type in a query clause, I get an error about not being able to cast an Int32 to the enum type. Mapping the field with a typeconverter doesn't help, as it appears that this is not used for transforming term values, only when storing or reading. There IS a bizarre work-around. If I cast BOTH sides of the term of the query to an object, it behaves correctly.

So, this results in an exception:

provider.SaQueryable<MyMappedType>().Where(x => x.EnumField != MyEnumType.SomeValue);

This does not:

provider.SaQueryable<MyMappedType>().Where(x => ((object)x.EnumField) != ((object)MyEnumType.SomeValue));
cherrydev commented 11 years ago

Associated stack-trace:

   at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
   at System.Int32.System.IConvertible.ToType(Type type, IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType)
   at Lucene.Net.Linq.Transformation.TreeVisitors.NoOpConvertExpressionRemovingVisitor.ConvertIfNecessary(Expression expression, Type type)
   at Lucene.Net.Linq.Transformation.TreeVisitors.NoOpConvertExpressionRemovingVisitor.VisitBinaryExpression(BinaryExpression expression)
   at Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitExpression(Expression expression)
   at Remotion.Linq.Clauses.WhereClause.TransformExpressions(Func`2 transformation)
   at Lucene.Net.Linq.Transformation.QueryModelTransformer.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
   at Remotion.Linq.Clauses.WhereClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
   at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
   at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
   at Remotion.Linq.QueryModel.Accept(IQueryModelVisitor visitor)
   at Lucene.Net.Linq.LuceneQueryExecutorBase`1.PrepareQuery(QueryModel queryModel)
   at Lucene.Net.Linq.LuceneQueryExecutorBase`1.ExecuteScalar[T](QueryModel queryModel)
   at Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo.ExecuteScalarQueryModel[T](QueryModel queryModel, IQueryExecutor executor)
   at Remotion.Linq.Clauses.StreamedData.StreamedScalarValueInfo.ExecuteQueryModel(QueryModel queryModel, IQueryExecutor executor)
   at Remotion.Linq.QueryModel.Execute(IQueryExecutor executor)
   at Remotion.Linq.QueryProviderBase.Execute(Expression expression)
   at Remotion.Linq.QueryProviderBase.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
chriseldredge commented 11 years ago

Fixed in b5f939b12fc1473aa7f79a446e68fc9cac47e24a, will close issue after releasing to nuget.org.

cherrydev commented 10 years ago

Fantastic, thanks. Any plans to make a release soon?

chriseldredge commented 10 years ago

Thanks for the nudge... been busy with other work recently, but since nothing else has come up on this project I'll try to release this week.

chriseldredge commented 10 years ago

Released: https://nuget.org/packages/Lucene.Net.Linq/3.2.54