Het volgende is een HqlGenerator die dit probleem oplost:
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()
});
}
}
Voeg dit toe aan uw HQLGeneratorsRegistry en u bent klaar om te gaan met oproepen naar string.Concat in uw LINQ-statements.
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();
}