-1

我正在尝试使用 fluentmapping 连接到 oracle 中的现有数据库。我得到了客户的映射

public CustomerMapping()
    {

         Not.LazyLoad();
        Id(x => x.Cst_Recid).GeneratedBy.Increment() ;
    }

我正在尝试创建会话

public static ISessionFactory CreateSessionFactory()
    {
        return Fluently
            .Configure()
            .Database(OracleClientConfiguration.Oracle10.ConnectionString
            ("...."))
            .Mappings(m =>
             {
                 m.FluentMappings.AddFromAssemblyOf<CustomerMapping>();

             })
             .BuildConfiguration() 
             .BuildSessionFactory();
    }

我有一些试用课程可以尝试创建 sessionFactory

public class MyDataProvider
{
    public static  Customer GetCustomerById(long customerId)
    {
        ISessionFactory sessionFactory = SessionFactory.CreateSessionFactory(); 
        ISession session = sessionFactory.OpenSession();
          return session.Linq<Customer>().Where(x => x.Cst_Recid.Equals(temp)).FirstOrDefault();

    }


}

即使我要打开会话并激活,我也无法通过 ID 获取客户...

测试非常简单——只检查选择活动

    [Test]
    public void CanGetCustomerById()
    {
        MyDataProvider provider = new MyDataProvider();
        Assert.AreEqual(33941, MyDataProvider.GetCustomerById(33941).Cst_Recid);

    }

有一个错误 -

TestCase '...DataLayer.Tests.CustomerMappingTests.CanGetCustomerById' 失败:NHibernate.ADOException:无法执行查询 [ select * from ( SELECT this_.Cst_Recid as Cst1_0_0_, this_.Cst_Customerid as Cst2_0_0_, this_.Cst_First_Name as Cst3_0_0_, this_.Cst_Group_Recid如Cst4_0_0_,this_.Cst_Insdbdt如Cst5_0_0_,this_.Cst_Insdbuser如Cst6_0_0_,this_.Cst_Joingroup_Dt如Cst7_0_0_,this_.Cst_Last_Name如Cst8_0_0_,this_.Cst_Lastupddt如Cst9_0_0_,this_.Cst_Lastupduser如Cst10_0_0_,this_.Cst_Tat_Lakoach_Meshalem如Cst11_0_0_,this_.Cst_Typeid如Cst12_0_0_ , this_.Cst_Tziyun_Meshalem_Rashi_Only as Cst13_0_0_, this_.Cst_Tziyun_Mizdamen as Cst14_0_0_ FROM "Customer" this_ WHERE this_.Cst_Recid = :p0 ) where rownum <=:p1 ] 位置参数:#0>33941 [SQL: select * from (SELECT this_.Cst_Recid作为 Cst1_0_0_,this_.Cst_Customerid如Cst2_0_0_,this_.Cst_First_Name如Cst3_0_0_,this_.Cst_Group_Recid如Cst4_0_0_,this_.Cst_Insdbdt如Cst5_0_0_,this_.Cst_Insdbuser如Cst6_0_0_,this_.Cst_Joingroup_Dt如Cst7_0_0_,this_.Cst_Last_Name如Cst8_0_0_,this_.Cst_Lastupddt如Cst9_0_0_,THIS_。 Cst_Lastupduser如Cst10_0_0_,this_.Cst_Tat_Lakoach_Meshalem如Cst11_0_0_,this_.Cst_Typeid如Cst12_0_0_,this_.Cst_Tziyun_Meshalem_Rashi_Only如Cst13_0_0_,this_.Cst_Tziyun_Mizdamen如Cst14_0_0_ FROM “客户” THIS_ WHERE this_.Cst_Recid =:P0)其中ROWNUM <=:P1] --- -> System.Data.OracleClient.OracleException:ORA-00942:表或视图不存在Cst_Joingroup_Dt为Cst7_0_0_,this_.Cst_Last_Name为Cst8_0_0_,this_.Cst_Lastupddt为Cst9_0_0_,this_.Cst_Lastupduser为Cst10_0_0_,this_.Cst_Tat_Lakoach_Meshalem为Cst11_0_0_,this_.Cst_Typeid为Cst12_0_0_,this_.Cst_Tziyun_Meshalem_Rashi_Only为Cst13_0_0_,this_.Cst_Tziyun_Mizdamen为Cst14_0_0_ FROM “客户” THIS_ WHERE this_.Cst_Recid = :p0 ) where rownum <=:p1] ----> System.Data.OracleClient.OracleException : ORA-00942: 表或视图不存在Cst_Joingroup_Dt为Cst7_0_0_,this_.Cst_Last_Name为Cst8_0_0_,this_.Cst_Lastupddt为Cst9_0_0_,this_.Cst_Lastupduser为Cst10_0_0_,this_.Cst_Tat_Lakoach_Meshalem为Cst11_0_0_,this_.Cst_Typeid为Cst12_0_0_,this_.Cst_Tziyun_Meshalem_Rashi_Only为Cst13_0_0_,this_.Cst_Tziyun_Mizdamen为Cst14_0_0_ FROM “客户” THIS_ WHERE this_.Cst_Recid = :p0 ) where rownum <=:p1] ----> System.Data.OracleClient.OracleException : ORA-00942: 表或视图不存在p1] ----> System.Data.OracleClient.OracleException : ORA-00942: 表或视图不存在p1] ----> System.Data.OracleClient.OracleException : ORA-00942: 表或视图不存在

他试图运行的查询是由 FluentNHibernate 自动构建的。如果我删除查询正确执行的引号,它会得到结果..问题是我无法根据需要更改查询..问题可能是我们使用的是 Oracle 11 g 而 FluentNhibernate 仅调整为 Oracle 9 或10 ?

将感谢任何帮助。

4

1 回答 1

2

我之前的回答是错误的。请允许我再试一次!

当您在 Oracle 中引用对象名称时,它会区分大小写。您的 CUSTOMER 表被引用为“Customer”,这与引用“CUSTOMER”不同:

SQL> select * from "dual";
select * from "dual"
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from "Dual";
select * from "Dual"
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from "DUAL";

D
-
X

我仍然对 Fluid NHibernate 一无所知,但是否有可能让它寻找“客户”表而不是“客户”表?

或者,如果没有其他东西正在寻找 CUSTOMERS 表,您可以将其重命名为“Customers”......但是,这将破坏对 CUSTOMERS 表的引用:

SQL> create table CUSTOMERS (x int);

Table created.

SQL> insert into CUSTOMERS (x) values (1);

1 row created.

SQL> select * from CUSTOMERS;

         X
----------
         1

SQL> select * from "Customers";
select * from "Customers"
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from "CUSTOMERS";

         X
----------
         1

SQL> alter table CUSTOMERS rename to "Customers";

Table altered.

SQL> select * from CUSTOMERS;
select * from CUSTOMERS
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from "Customers";

         X
----------
         1

祝你好运!我希望这有帮助...

于 2009-10-08T13:50:45.317 回答