我正在尝试使用流畅的映射连接到oracle中的现有数据库。 我有 在CUstomer上映射
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(如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 SELECT this_.Cst_Recid如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&lt; =:p1] 位置参数:#0&gt; 33941 [SQL:选择从*(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&lt; =:p1] ----&GT; System.Data.OracleClient.OracleException:ORA-00942:表或视图不存在
他试图运行的查询是由FluentNHibernate自动构建的。如果我删除quoates查询执行正确,它得到结果..麻烦是我不能改变我想要的查询..也许问题是我们使用Oracle 11 g和FluentNhibernate仅调整到Oracle 9或10?
将会获得任何帮助。
答案 0 :(得分: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一无所知,但它是否可以让它寻找“CUSTOMER”表而不是“Customers”表?
或者,如果没有其他内容正在寻找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
祝你好运!我希望这有帮助...