Следва HqlGenerator, който решава този проблем:
public class ConcatHqlGenerator : BaseHqlGeneratorForMethod
{
public ConcatHqlGenerator()
: base()
{
this.SupportedMethods = new[]
{ ReflectionHelper.GetMethodDefinition(() => string.Concat(null, null)) };
}
public override HqlTreeNode BuildHql(MethodInfo method,
Expression targetObject,
ReadOnlyCollection<Expression> arguments,
HqlTreeBuilder treeBuilder,
IHqlExpressionVisitor visitor)
{
return treeBuilder.Concat(
new[]
{
visitor.Visit(arguments[0]).AsExpression(),
visitor.Visit(arguments[1]).AsExpression()
});
}
}
Добавете това към вашия HQLGeneratorsRegistry и ще бъдете добре да започнете с извиквания към string.Concat във вашите LINQ оператори.
public class LinqToHqlGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry
{
public LinqToHqlGeneratorsRegistry()
: base()
{
this.Merge(new ConcatHqlGenerator());
}
}
private static ISessionFactory CreateSessionFactory()
{
var configuration = new NHib.Cfg.Configuration();
configuration.Properties.Add(NHibernate.Cfg
.Environment.LinqToHqlGeneratorsRegistry,
typeof(LinqToHqlGeneratorsRegistry).AssemblyQualifiedName);
configuration.Configure();
return configuration.BuildSessionFactory();
}