A dialect's purpose is to manage the nuances between different Sql
languages. You're using it as a customization to an existing Sql language.
Basically think of it like this, it's intent isn't for you to add
functionality to that doesn't already exist, it's for you to register
differences in functionality between different query languages.

What you're looking to do with registering your own function for use
elsewhere in your mappings would probably lead you to use a Database
object<http://ayende.com/Blog/archive/2009/04/16/nhibernate-mapping-ltdatabase-objectgt.aspx>
.

On Fri, Dec 4, 2009 at 7:21 AM, Kristoffer Ahl <[email protected]> wrote:

> I want to be able to call a custom function called "recent_date" as
> part of my HQL. Like this: [Date] >= recent_date()
>
> I created a new dialect, inheriting from MsSql2000Dialect and
> specified the dialect for my configuration.
>
> public class NordicMsSql2000Dialect : MsSql2000Dialect
> {
>    public NordicMsSql2000Dialect()
>    {
>        RegisterFunction(
>                "recent_date",
>                new SQLFunctionTemplate(
>                        NHibernateUtil.Date,
>                        "dateadd(day, -15, getdate())"
>                        )
>                );
>    }
> }
>
> var configuration = Fluently.Configure()
> .Database(
>    MsSqlConfiguration.MsSql2000
>    .ConnectionString(c => .... )
>    .Cache(c => c.UseQueryCache().ProviderClass<HashtableCacheProvider>
> ())
>    .Dialect<NordicMsSql2000Dialect>()
> )
> .Mappings(m => ....)
> .BuildConfiguration();
>
> When calling recent_date() I get the following error:
> System.Data.SqlClient.SqlException: 'recent_date' is not a recognized
> function name
>
> I'm using it in a where statement for a HasMany-mapping like below.
>
> HasMany(x => x.RecentValues)
>    .Access.CamelCaseField(Prefix.Underscore)
>    .Cascade.SaveUpdate()
>    .Where("Date >= recent_date()");
>
> What am I missing here?
>
> PS. I've also posted this question on Stackoverflow if you prefer to
> answer it there. Thanks!
>
> http://stackoverflow.com/questions/1845884/custom-sql-function-for-nhibernate-dialect
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<fluent-nhibernate%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
>
>
>


-- 
- Hudson
http://www.bestguesstheory.com
http://twitter.com/HudsonAkridge

--

You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.


Reply via email to