为什么 Fluent NHibernate with LINQ 返回空列表(使用 Oracle 数据库)?
我正在使用 Fluent NHibernate(NH3 版本 - #694)和 LINQ 连接到 Oracle 11 数据库。但是,我似乎无法从数据库中获取任何数据。连接似乎正常工作,因为如果我更改登录信息,则会引发错误。
我使用以下代码:
// Setup.
OracleClientConfiguration oracleClientConfiguration =
OracleClientConfiguration.Oracle10
.ShowSql()
.ConnectionString(connectionString);
_sessionFactory =
Fluently.Configure()
.Database(oracleClientConfiguration)
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<Feed>())
.BuildSessionFactory();
// Query.
using (ISession session = _sessionFactory.OpenSession())
{
IEnumerable<Category> categories = session.Query<Category>().ToList(); // Returns empty list.
// And so on...
}
我有一个类别表的映射,但是,无论我在其中放入什么,我仍然得到一个空列表。另外,即使我使用 ShowSql(),我也没有在 VS (2010) 窗口中看到任何 NHibernate 输出。
我正在使用 TestDriven.NET (3.x) 来运行代码。不会引发任何错误,并且返回集合上的 Assert.NotEmpty (xUnit) 失败(显然)。
我被困住了,因为代码正在运行,但什么也没返回,而且我无法获得任何诊断信息。我什至尝试让 NHibernate 写入 log4net (TraceAppender),但是,再一次,什么也没有。
我很感激任何指点——即使这是让这个东西告诉我它想要做什么的一种方式。
I'm using Fluent NHibernate (the NH3 build - #694) and LINQ to connect to an Oracle 11 database. However, I don't seem to be able to get any data from the database. The connection seems to be working, as, if I change my login info, it throws an error.
I'm using the following code:
// Setup.
OracleClientConfiguration oracleClientConfiguration =
OracleClientConfiguration.Oracle10
.ShowSql()
.ConnectionString(connectionString);
_sessionFactory =
Fluently.Configure()
.Database(oracleClientConfiguration)
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<Feed>())
.BuildSessionFactory();
// Query.
using (ISession session = _sessionFactory.OpenSession())
{
IEnumerable<Category> categories = session.Query<Category>().ToList(); // Returns empty list.
// And so on...
}
I have a map for the Category table, but, no matter what I put in there, I still get an empty list. Also, even though I use ShowSql(), I'm not seeing any NHibernate output in the VS (2010) window.
I'm using TestDriven.NET (3.x) to run the code. No errors are thrown and the Assert.NotEmpty (xUnit) on the returned collection fails (obviously).
I'm stuck, as the code is running and just returning nothing and I can't get any diagnostic info. I even tried getting NHibernate to write to log4net (TraceAppender), but, again, nothing.
I'd appreciate any pointers - even if it's a way of getting the thing to tell me what it's trying to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实证明,映射中使用的类之一被标记为“内部”。
Turns out that one of the classes used in the mapping was marked "internal".
您可以尝试用此替换代码的下部块吗?
乍一看,我怀疑问题是您使用了
ToList()
而不是List()
,但请告诉我这个建议是否能让您立即通过问题。Can you try replacing the lower block of your code with this?
At first glance I suspect the issue is your use of
ToList()
instead ofList<T>()
, but please let me know if this suggestion gets you past the immediate issue.检查 Fluent NHibernate xml 文件。我面临同样的问题,毕竟我意识到我的 xml 文件已经过时了。
Check the Fluent NHibernate xml files. I face the same problem and after all I realize that my xml files were out-of-date.