Hi pp,
I have some problems with the linq queries and the spatial datatypes. I want to make a search for all points in a certain distance. Here is a example:
this.pointObjectRepository.GetAllEntities().FirstOrDefault(x => x.Location.Distance(geoPoint1.Location) < 10);
pointObjectRepository is my repository and GetAllEntities is a session.Query() from nhibernate. geoPoint1 is from type NetTopologySuite.Geometries.Point. If I run it, I've got a NotSupportedException with 'Double Distance(GeoAPI.Geometries.IGeometry)'. It comes from
System.NotSupportedException: Double Distance(GeoAPI.Geometries.IGeometry)
bei NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitMethodCallExpression(MethodCallExpression expression)
bei NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
bei NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression)
bei NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
bei NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.Visit(Expression expression, VisitorParameters parameters)
bei NHibernate.Linq.Visitors.QueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
bei Remotion.Linq.Clauses.WhereClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
bei Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection1 bodyClauses, QueryModel queryModel) bei Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel) bei NHibernate.Linq.Visitors.QueryModelVisitor.Visit() bei NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, Boolean root) bei NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory) bei NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary
2 filters, ISessionFactoryImplementor factory)
bei NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary2 enabledFilters, ISessionFactoryImplementor factory) bei NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary
2 enabledFilters, ISessionFactoryImplementor factory)
bei NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, Boolean shallow, IDictionary2 enabledFilters, ISessionFactoryImplementor factory) bei NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary
2 enabledFilters)
bei NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow)
bei NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression)
bei NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery)
bei NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
bei NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)
bei System.Linq.Queryable.FirstOrDefault[TSource](IQueryable1 source, Expression
1 predicate)
the method object that is passed to if (!_functionRegistry.TryGetGenerator(method, out generator)) has a Fullname of 'NetTopologySuite.Geometries.Geometry.Distance(GeoAPI.Geometries.IGeometry)' but the registered method for distance has a litte bit other type: 'GeoAPI.Geometries.IGeometry.Distance(GeoAPI.Geometries.IGeometry)'
so the if-statement returns false and it crashed. How Can I Fix it?
The strange thing is:
var geoPoint1 = this.pointObjectRepository.FindByPrimaryKey(1);
var geoPoint2 = this.pointObjectRepository.FindByPrimaryKey(2);
Debug.WriteLine(geoPoint1.Location.Distance(geoPoint2.Location));
that works