Hello,
I have done that in HQL by sub-classing a NHibernate sql dialect to add
some custom functions. But it could be a bit tricky for developers who come
after you in the code and may not understood from where come your custom
HQL functions.
using System;
using System.Text.RegularExpressions;
using NHibernate.Dialect;
using NHibernate.Dialect.Function;
using NHibernate;
/// <summary>
/// Modify HQL dialect to allow for specifying custom collation.
/// </summary>
public class CustomMsSqlDialect : MsSql2005Dialect
{
/// <summary>
/// Default constructor.
/// </summary>
public CustomMsSqlDialect()
{
RegisterFunction("withcollation",
new WithCollationFunction());
}
}
/// <summary>
/// Add collation specification to an argument.
/// </summary>
[Serializable]
public class WithCollationFunction : SQLFunctionTemplate,
IFunctionGrammar
{
/// <summary>
/// Default constructor.
/// </summary>
public WithCollationFunction()
: base(NHibernateUtil.String, "?1 collate ?2")
{
}
bool IFunctionGrammar.IsSeparator(string token)
{
return false;
}
bool IFunctionGrammar.IsKnownArgument(string token)
{
return Regex.IsMatch(token,
"[A-Z][A-Z0-9_]+_(?:CS|CI)_(?:AS|AI)(?:_KS)?(?:_WS)?",
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
}
}
You specify it in your NHibernate configuration:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
...
<property
name="dialect">YourAssembly.YourNamespace.CustomMsSqlDialect,
YourAssembly</property>
...
</session-factory>
</hibernate-configuration>
And asample queries (on which I generally put a comment to warn about the
custom function; I have not translate this one) :
<!-- La fonction withCollation n'est pas du HQL standard, elle vient d'un
custom dialect. -->
<query name="theQueryName">
<![CDATA[
from Blah as b
where b.Name like withCollation(:partialName, french_ci_ai)
]]>
</query>
Le mardi 30 avril 2013 04:03:07 UTC+2, Diego Dias a écrit :
>
> Hi, Guys.
>
> I need extend Like restriction to support accent insensitive, but I don't
> know where tinkering. Anyone know how I do this?
>
> --
>
> *Diego Dias
> *Analista Desenvolvedor
> Microsoft Certified Applications Developer
> Microsoft Certified Technology Specialist WCF .Net 4.0 - Charter
> Member<http://www.microsoft.com/learning/en/us/certification/cert-program-membership.aspx>
> 11-8931.1768
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.