在 oracle 中的旧数据库上使用流畅的 Nhibernate
我正在尝试使用 fluencemapping 连接到 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 as Cst4_0_0_, this_.Cst_Insdbdt as Cst5_0_0_, this_.Cst_Insdbuser as 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_仅作为 Cst13_0_0_,this_.Cst_Tziyun_Mizdamen 作为 Cst14_0_0_ 来自“客户”this_ WHERE this_.Cst_Recid = : p0 ) 其中 rownum <=:p1 ] 位置参数:#0>33941 [SQL: 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 as Cst4_0_0_, this_.Cst_Insdbdt as Cst5_0_0_, this_.Cst_Insdbuser as 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_ 来自“客户”this_ WHERE this_.Cst_Recid = :p0 ) 其中 rownum <=:p1] ----> System.Data.OracleClient.OracleException:ORA-00942:表或视图不存在,
他尝试运行的查询是由 FluentNHibernate 自动构建的。如果我删除引号,查询将正确执行,它会得到结果..问题是我无法根据需要更改查询..也许问题是我们正在使用 Oracle 11 g 和 FluentNhibernate 仅调整到 Oracle 9 或10?
将不胜感激任何帮助。
I am trying to connect to the existing db in oracle with fluentmapping .
I got
Mapping over CUstomer
public CustomerMapping()
{
Not.LazyLoad();
Id(x => x.Cst_Recid).GeneratedBy.Increment() ;
}
and i am trying to create session
public static ISessionFactory CreateSessionFactory()
{
return Fluently
.Configure()
.Database(OracleClientConfiguration.Oracle10.ConnectionString
("...."))
.Mappings(m =>
{
m.FluentMappings.AddFromAssemblyOf<CustomerMapping>();
})
.BuildConfiguration()
.BuildSessionFactory();
}
i have some trial class to try and create the 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();
}
}
i am not being able to get the Customer by Id even though I am getting to open session and activating ...
the test is very simple - only to check the select activity
[Test]
public void CanGetCustomerById()
{
MyDataProvider provider = new MyDataProvider();
Assert.AreEqual(33941, MyDataProvider.GetCustomerById(33941).Cst_Recid);
}
there is a mistake -
TestCase '...DataLayer.Tests.CustomerMappingTests.CanGetCustomerById'
failed: NHibernate.ADOException : could not execute query
[ 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 as Cst4_0_0_, this_.Cst_Insdbdt as Cst5_0_0_, this_.Cst_Insdbuser as Cst6_0_0_, this_.Cst_Joingroup_Dt as Cst7_0_0_, this_.Cst_Last_Name as Cst8_0_0_, this_.Cst_Lastupddt as Cst9_0_0_, this_.Cst_Lastupduser as Cst10_0_0_, this_.Cst_Tat_Lakoach_Meshalem as Cst11_0_0_, this_.Cst_Typeid as 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 ]
Positional parameters: #0>33941
[SQL: 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 as Cst4_0_0_, this_.Cst_Insdbdt as Cst5_0_0_, this_.Cst_Insdbuser as Cst6_0_0_, this_.Cst_Joingroup_Dt as Cst7_0_0_, this_.Cst_Last_Name as Cst8_0_0_, this_.Cst_Lastupddt as Cst9_0_0_, this_.Cst_Lastupduser as Cst10_0_0_, this_.Cst_Tat_Lakoach_Meshalem as Cst11_0_0_, this_.Cst_Typeid as 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]
----> System.Data.OracleClient.OracleException : ORA-00942: table or view does not exist
the query that he is trying to run is build automaticly by FluentNHibernate . If i remove the quoates the query executes right , it gets the result .. the trouble is that i can not change the query as i want .. maybe the problem is that we are using Oracle 11 g and FluentNhibernate adjusted only to Oracle 9 or 10 ?
will appreceate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我之前的回答是不正确的。请允许我再试一次!
当您在 Oracle 中引用对象名称时,它会区分大小写。您的 CUSTOMER 表被引用为“Customer”,这与引用的“CUSTOMER”不同:
我仍然对 Fluid NHibernate 一无所知,但是是否有可能让它查找“CUSTOMER”表而不是“客户”表?
或者,如果没有其他东西在寻找 CUSTOMERS 表,您可以将其重命名为“Customers”...但是,这将破坏对 CUSTOMERS 表的引用:
祝你好运!我希望这有帮助...
My previous answer was incorrect. Allow me to try again!
When you quote an object name in Oracle, it becomes case-sensative. Your CUSTOMER table is being quoted as "Customer" which is not the same as being quoted "CUSTOMER":
I still don't know anything about Fluid NHibernate, but is it possible to get it to look for a "CUSTOMER" table instead of a "Customers" table?
Alternatively, if nothing else is looking for a CUSTOMERS table, you could rename it to "Customers"... however, this will break references to a CUSTOMERS table:
Good luck! I hope this helps...