NHibernate的 - 强制逃避的表名NHibernate

2023-09-04 02:43:57 作者:孤猫

有没有对如何在网上使用(NHibernate.Criterion.IdentifierEqEx pression)任何好的例子吗?我找不到任何。 我对你应该做的传入构造有点糊涂了。

Are there any good examples of how to use this (NHibernate.Criterion.IdentifierEqExpression) online? I couldn't find any. I'm a little confused about what you are supposed to pass into the constructor.

我通过在1一个Int32,我一直在想我的测试应该基本上做 其中id = 1的查询类型,而是它吹了其中id =?和一些关于位置参数。如果这不是什么应该被传递到构造...是什么?

I pass in an int32 of 1 and I keep thinking my test should basically do a "where id = 1" type of query and instead it blows up with "where id = ?" and something about positional parameters. If that's not what is supposed to be passed into the constructor ... what is?

真正的问题 当我看到SQL输出它似乎是除了我的表被命名为用户和NHibernate不封闭它像[用户]其实正常工作。任何方式强迫吗?

Real Issue When I look at SQL output it seems to be working correctly except for the fact my table is named User and NHibernate isn't enclosing it like [User]. Any way to force this?

推荐答案

指定表名作为`用户`。例如:

Specify the table name as `User`. For example:

(HBM)
<class name="User" table="`User`">

(Fluent)
public UserMap()
{
    WithTable("`User`");
    ...

(Mapping By Code)
public UserMap()
{
    Table("`User`");
    ...

同样,列你就必须做一些事情,如:

Similarly, with columns you'll have to do something like:

Map(x => x.IsCurrent, "`Current`");

呵呵与传统的DB工作的乐趣。

Oh the joys of working with legacy DBs.