Hi,
I am trying to configure NHibernate on my console application in which I am trying to map an Employee class to a table Employee.
I am getting below exception which I have no clue:
Class:
class Employee
{
public int id;
public string name;
public Employee manager;
public string SayHello()
{
return string.Format(
"'Hello World!', said {0}.", name);
}
}
TABLE:
CREATE TABLE Employee (
id int identity primary key,
name varchar(50),
manager int )
GO
Mapping File:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
auto-import="true">
<class name="ConsoleApplication.Employee, ConsoleApplication1" lazy="false">
<id name="id" access="field">
<generator class="native" />
</id>
<property name="name" access="field" column="name"/>
<many-to-one access="field" name="manager" column="manager"
cascade="all"/>
</class>
</hibernate-mapping>
App.config
<?xml version="1.0" ?>
<configuration>
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">
Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AAM;Data Source=(local)
</property>
<property name="dialect">
NHibernate.Dialect.MsSql2005Dialect
</property>
<property name="show_sql">
false
</property>
</session-factory>
</hibernate-configuration>
</configuration>
Error:
Message: could not execute query
[ select employee0_.id as id0_, employee0_.name as name0_, employee0_.manager as manager0_ from Employee employee0_ ]
[SQL: select employee0_.id as id0_, employee0_.name as name0_, employee0_.manager as manager0_ from Employee employee0_]
StackTrace: at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results)
at NHibernate.Impl.SessionImpl.List(String query, QueryParameters queryParameters, IList results)
at NHibernate.Impl.SessionImpl.List[T](String query, QueryParameters parameters)
at NHibernate.Impl.QueryImpl.List[T]()
at ConsoleApplication.Program.LoadEmployeesFromDatabase() in C:\Mahesh\Code\HelloNHibernate\ConsoleApplication1\Program.cs:line 50
at ConsoleApplication.Program.Main(String[] args) in C:\Mahesh\Code\HelloNHibernate\ConsoleApplication1\Program.cs:line 18
Inner Exception: Invalid object name 'Employee'
I have the Employee in my database and when I run the query which runtime given in the message property executing successfully.
Any thoughts on this??
Thanks, Mahesh