Why is Fluent NHibernate with LINQ returning an empty list (with Oracle database)?
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()
开发者_如何学C .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.
Turns out that one of the classes used in the mapping was marked "internal".
Can you try replacing the lower block of your code with this?
using (ISession session = _sessionFactory.OpenSession())
{
IEnumerable<Category> categories = session.CreateCriteria(typeof(Category)).List<Category>();
}
At first glance I suspect the issue is your use of ToList()
instead of List<T>()
, but please let me know if this suggestion gets you past the immediate issue.
Check the Fluent NHibernate xml files. I face the same problem and after all I realize that my xml files were out-of-date.
精彩评论