same link से rebelliard answer प्रदान से, Shuager भी कुछ इसी तरह करने के लिए एक कस्टम समारोह को परिभाषित करने के लिए एक तरह से आपूर्ति करती है। इसका एचक्यूएल में प्रयोग करने योग्य होने का लाभ भी है।
उनकी कस्टम समारोह कार्यान्वयन अपने प्रश्न और मेरी अपनी जरूरतों के लिए भी विशिष्ट था, इसलिए यहां कार्यान्वयन मैं के साथ समाप्त हो गया है:
/// <summary>
/// Customized dialect for allowing changing collation on <c>like</c> statements.
/// </summary>
public class CustomMsSqlDialect : MsSql2008Dialect
{
/// <summary>
/// Default constructor.
/// </summary>
public CustomMsSqlDialect()
{
RegisterFunction("withcollation",
new WithCollationFunction());
}
}
/// <summary>
/// Add collation to string 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);
}
}
मन बोली आधार वर्ग, मैं मई 2008 बोली का इस्तेमाल किया है, तो आप इसे बदलना चाहते हैं। अपनी एचक्यूएल बोली को अपनी नई कस्टम बोली में बदलने के लिए मत भूलना (उदाहरण के लिए अपने सत्र-कारखाने की "बोली" कॉन्फ़िगरेशन संपत्ति का उपयोग करना)। HQL में
उदाहरण उपयोग, मिलान अनुकूलन के बिना मानक क्वेरी:
from Cat as c
where c.Name like 'fel%'
कस्टम मिलान Nhib 3.2 के साथ
from Cat as c
where c.Name like withCollation('fel%', French_CI_AI)
वर्क्स के साथ।
स्रोत
2012-08-24 16:10:23
धन्यवाद। कि एक राहत की बात है! –