Thiago Burgo
Thiago Burgo

Reputation: 91

FluentNHibernate configure LinqToHqlGeneratorsRegistry and Custom Linq STDistance Spatial SQL Server 2008

I want to create a new Linq custom method with LinqToHqlGeneratorsRegistry, to use SQL Server 2008 STDistance geography function, How can I do:

1) Map my high level method (Coordinate.DistanceTo(other) instance method) to be exchanged by geoPoint.STDistance(otherGeoPoint) in SQL Server? My attempts are this:

public class DistanceMethodGenerator : BaseHqlGeneratorForMethod
{
    public DistanceMethodGenerator()
    {
        base.SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<ICoordinate>(coordinate => coordinate.DistanceTo(null)) };
    }
    public override HqlTreeNode BuildHql(MethodInfo method, System.Linq.Expressions.Expression targetObject, ReadOnlyCollection<System.Linq.Expressions.Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
    {

        //what to do here to tranform: coord.DistanceTo(otherCoord) in sql     //coord.STDistance(otherCoord)?
        return ????
    }
}
public sealed class LinqToSqlGeneratorRegistrypublic : DefaultLinqToHqlGeneratorsRegistry
{
    public LinqToSqlGeneratorRegistrypublic()
    {
        RegisterGenerator(ReflectionHelper.GetMethodDefinition<ICoordinate>(coordinate => coordinate.DistanceTo(null)),
                          new DistanceMethodGenerator());
    }
}

2) How register that with fluentNHibernate, I cannot found a method like LinqToHqlGeneratorsRegistry<LinqToSqlGeneratorRegistrypublic >() in FluentNHibernate

Thanks!

Upvotes: 1

Views: 873

Answers (1)

Ricardo Peres
Ricardo Peres

Reputation: 14535

Try this:

.ExposeConfiguration(c =>
{
  c.Properties.Add(NHibernate.Cfg.Environment.LinqToHqlGeneratorsRegistry, typeof(LinqToSqlGeneratorRegistrypublic).AssemblyQualifiedName)
}

Upvotes: 1

Related Questions