Johan Nordberg
Johan Nordberg

Reputation: 3777

NHibernate mapping with getdate() sql function in where-attribute

I have a mapping that retrieves all active roles for a user. I use the where attribute to filter out roles in the hbm mapping. The mapping look like this:

<map name="Bar" table="Foo_Bar" lazy="true" cascade="all" inverse="false" where="intGroupId Is Null And dtmExpires > getdate()">
<cache usage="read-write"/>
<key column="intUserId"/>
<index column="varRole" type="string"/>
<one-to-many class="Foo.Bar, Foo"/>
</map>

This works great in production on a SQL Server, but in my unit tests where I use SQLite the getdate() function isn't recognized.

How can I modify my mapping so it works in both MS SQL Server and SQLite, but still have the filter?

// Johan

Upvotes: 0

Views: 806

Answers (1)

AlexCuse
AlexCuse

Reputation: 18296

I don't know much about SQLite but you may be able to use

intGroupId Is Null And dtmExpires > CURRENT_TIMESTAMP

CURRENT_TIMESTAMP is the SQL Standard equivalent of getdate(), and I believe it is implemented in SQLite (and I'm positive it is in SQL Server).

You may be able to use the technique discussed here to tweak your mappings at runtime if this doesn't work.

Upvotes: 1

Related Questions