1

我想创建一个新的 Linq 自定义方法LinqToHqlGeneratorsRegistry,以使用 SQL Server 2008STDistance地理功能,我该怎么做:

1)映射我的高级方法(Coordinate.DistanceTo(other)实例方法)以geoPoint.STDistance(otherGeoPoint)在 SQL Server 中交换?我的尝试是这样的:

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)如何用fluentNHibernate注册,我找不到像LinqToHqlGeneratorsRegistry<LinqToSqlGeneratorRegistrypublic >()FluentNHibernate这样的方法

谢谢!

4

1 回答 1

1

尝试这个:

.ExposeConfiguration(c =>
{
  c.Properties.Add(NHibernate.Cfg.Environment.LinqToHqlGeneratorsRegistry, typeof(LinqToSqlGeneratorRegistrypublic).AssemblyQualifiedName)
}
于 2013-07-17T07:16:58.577 回答