I keep getting this error and I can't find the problem. I need another pair of eyes on this.
The error:
Quote:
Incorrect syntax near the keyword 'Order'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'Order'.
Source Error:
Line 32: ITransaction transaction = session.BeginTransaction();
Line 33:
Line 34: Customer customer = (Customer)session.Load(typeof(Customer), customerId);
Line 35:
Line 36: transaction.Commit();
Source File: C:\My Visual Studio Projects\CustomerExample\CustomerExample\BLL\CustomerFacade.cs Line: 34
Stack Trace:
[SqlException (0x80131904): Incorrect syntax near the keyword 'Order'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +95
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +82
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +52
System.Data.SqlClient.SqlDataReader.get_MetaData() +130
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +371
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1119
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +45
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +162
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +35
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +29
NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd) +92
NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session) +238
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) +354
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) +89
NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object[] ids, IType[] types) +73
NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type) +99
NHibernate.Loader.OneToManyLoader.Initialize(Object id, ISessionImplementor session) +35
NHibernate.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session) +61
[ADOException: could not initialize collection: [CustomerExample.BOL.Customer.Orders#2]]
NHibernate.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session) +154
NHibernate.Impl.SessionImpl.InitializeCollection(PersistentCollection collection, Boolean writing) +325
NHibernate.Collection.PersistentCollection.ForceInitialization() +201
NHibernate.Impl.SessionImpl.InitializeNonLazyCollections() +192
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) +137
NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object[] values, IType[] types, Object optionalObject, Object optionalID) +85
NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Object optionalIdentifier) +117
NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId) +63
NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject) +45
NHibernate.Persister.EntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session) +276
NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted) +720
NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) +181
NHibernate.Impl.SessionImpl.Load(Type clazz, Object id) +128
CustomerExample.BLL.CustomerFacade.GetCustomer(Int32 customerId) in C:\My Visual Studio Projects\CustomerExample\CustomerExample\BLL\CustomerFacade.cs:34
CustomerExample._Default.BindOrders() in C:\My Visual Studio Projects\CustomerExample\CustomerExample\Default.aspx.cs:27
CustomerExample._Default.Page_Load(Object sender, EventArgs e) in C:\My Visual Studio Projects\CustomerExample\CustomerExample\Default.aspx.cs:21
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +31
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +68
System.Web.UI.Control.OnLoad(EventArgs e) +88
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3034
The Order Mapping File
Quote:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="CustomerExample.BOL.Order, CustomerExample" table="Order">
<id name="Id" type="Int32" column="Id" >
<generator class="identity" />
</id>
<property name="CustomerId" column="CustomerId" type="Int32" />
<property name="Product" column="Product" type="String" length="50"/>
<property name="Price" column="Price" type="Double" />
</class>
</hibernate-mapping>
The Customer Mapping File
Quote:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="CustomerExample.BOL.Customer, CustomerExample" table="Customer">
<id name="Id" type="Int32" column="Id" >
<generator class="identity" />
</id>
<property name="Name" column="Name" type="String" length="50"/>
<set name="Orders">
<key column="CustomerId" />
<one-to-many
class="CustomerExample.BOL.Order, CustomerExample" />
</set>
</class>
</hibernate-mapping>
The errors occurs when the customer object is trying to load.
Code:
public Customer GetCustomer(int customerId)
{
try
{
ISession session = ManagerSingleton.Instance.OpenSession();
ITransaction transaction = session.BeginTransaction();
Customer customer = (Customer)session.Load(typeof(Customer), customerId);
transaction.Commit();
session.Close();
return customer;
}
catch(SqlException ex)
{
throw ex;
}
}