开发者

Fluent NHibernate RegisterFunction SQLFunctionTemplate usage

I've seen this opportunity reported at least half a dozen times with about as many responses.

My problem is, I've got a MySQL database function defined, we'll call it "my_func(int val) returns int", which works fine if I test directly on the database.

I've also gotten it to work with a direct SQL passthrough my repository implementation, which is okay, but I'd rather开发者_运维百科 route it through Hql, for some god-awful reason...

So... I've got a MySQL5Dialect setup to register the function and I'm having some difficulty parsing through the expected conventions.

My understanding is that I need to prefix the function name with "dbo." at some point during the function registration?

Something like this,

//...
RegisterFunction("my_func", new SQLFunctionTemplate(NHibernateUtil.Int32, "my_func(?1)"));
//...

And then through my repository,

var value = repository.FindByHQL<int>("select my_func(2)").Single();

Where FindByHQL returns an IList.

Any thoughts why this wouldn't work.

I'm running the latest WAMP (2.1e I think).

Enough info? Let me know if I can provide any further details.

Thanks,

Michael


select my_func(2)

is not valid HQL, regardless of whether the function is registered or not.

You can use SQL instead if that's your use case.

Post full exception with stack trace if it's not and this was just a simplified example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜