C# nhibernate与mysql数据库
我的代码有一个错误,我不知道为什么 我的代码由两个文件组成:C# nhibernate与mysql数据库,c#,mysql,visual-studio-2010,nhibernate,phpmyadmin,C#,Mysql,Visual Studio 2010,Nhibernate,Phpmyadmin,我的代码有一个错误,我不知道为什么 我的代码由两个文件组成: systemprop.cs System.hbm.xml 但我有以下错误: 将[propertyID]列为第1列,将[value]列为第2列,将[propertyID]列为第19列,将[value]列为第2列,将[systemprop0]列为第1列 这意味着我在第1行的“[propertyID]作为第1列,systemprop0作为第2列,systemprop0作为第19列,[value]附近有一个语法错误 这是我的密码: 类Sys
systemprop.cs
System.hbm.xml
“[propertyID]作为第1列,systemprop0作为第2列,systemprop0作为第19列,[value]附近有一个语法错误
这是我的密码:
类Systemprop
:
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using DATA;
namespace DATA
{
public partial class Systemprop
{
private string PropertyID { set; get; }
private string Value { set; get; }
private string Description { set; get; }
private int LastUpdateTime { set; get; }
private int CreationTime { set; get; }
// public Systemprop() { }
public static ISessionFactory SessionFactory;
public static ISession OpenSession()
{
if (SessionFactory == null)
{
Configuration config = new Configuration();
config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MySQLDialect");
config.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.MySqlDataDriver");
config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Server=localhost;Database=opengts;Uid=root;Pwd=;");
config.AddAssembly("DATA");
SessionFactory = config.BuildSessionFactory();
}
return SessionFactory.OpenSession();
}
public static IList<Systemprop> GetSystemprop()
{
using (ISession session = OpenSession())
{
if (session != null)
{
IQuery query = session.CreateQuery("FROM Systemprop");
IList<Systemprop> pets = query.List<Systemprop>();
return pets;
}
}
return null;
}
}
}
但我有一个错误:
[MySqlException (0x80004005): Erreur de syntaxe près de '[propertyID] as column1_19_, systemprop0_.[value] as column2_19_, systemprop0_.[' à la ligne 1]
MySql.Data.MySqlClient.MySqlStream.ReadPacket() +277
MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId) +73
MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId) +20
MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) +100
MySql.Data.MySqlClient.MySqlDataReader.NextResult() +742
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +1620
MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +4
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +12
NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) +292
NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) +244
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +186
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +129
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +116
[GenericADOException: could not execute query
[ select systemprop0_.[propertyID] as column1_19_, systemprop0_.[value] as column2_19_, systemprop0_.[description] as column3_19_, systemprop0_.[lastUpdateTime] as column4_19_, systemprop0_.[creationTime] as column5_19_ from [dbo].[systemprops] systemprop0_ ]
[SQL: select systemprop0_.[propertyID] as column1_19_, systemprop0_.[value] as column2_19_, systemprop0_.[description] as column3_19_, systemprop0_.[lastUpdateTime] as column4_19_, systemprop0_.[creationTime] as column5_19_ from [dbo].[systemprops] systemprop0_]]
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +213
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +18
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) +79
NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) +51
NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) +231
NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) +369
NHibernate.Impl.SessionImpl.List(String query, QueryParameters queryParameters, IList results) +317
NHibernate.Impl.SessionImpl.List(String query, QueryParameters parameters) +282
NHibernate.Impl.QueryImpl.List() +163
DATA.SystempropExtensions.GetSystemprop() in C:\Users\HP\Desktop\our_project\DATA\Queries\Systemprop.cs:37
MvcApplication7.Controllers.AccueilController.Index() in C:\Users\HP\Desktop\our_project\MvcApplication7\Controllers\AccueilController.cs:16
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841105
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
[MySqlException(0x80004005):将[propertyID]列为第1列,将[propertyID]列为第19列,将[value]列为第2列,将[propert0]列为第19列。['la ligne 1]
MySql.Data.MySqlClient.MySqlStream.ReadPacket()+277
MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&affectedRow,Int32&insertedId)+73
MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId、Int32&affectedRows、Int32&insertedId)+20
MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId,Boolean force)+100
MySql.Data.MySqlClient.MySqlDataReader.NextResult()+742
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior)+1620
MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior)+4
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()+12
NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)+292
NHibernate.Loader.Loader.GetResultSet(IDBST命令,布尔自动发现类型,布尔可调用,行选择,ISessionImplementor会话)+244
NHibernate.Loader.Loader.DoQuery(ISessionImplementor会话,QueryParameters QueryParameters,Boolean returnProxies)+186
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor会话、QueryParameters QueryParameters、Boolean returnProxies)+129
NHibernate.Loader.Loader.DoList(ISessionImplementor会话,QueryParameters QueryParameters)+116
[GenericADOException:无法执行查询
[选择systemprop0.[propertyID]作为第1列,systemprop0.[value]作为第2列,systemprop0.[description]作为第3列,systemprop0.[lastUpdateTime]作为第4列,systemprop0.[creationTime]作为第5列,来自[dbo][systemprops]systemprop0.]
[SQL:选择systemprop0.[propertyID]作为第1列,systemprop0.[value]作为第2列,systemprop0.[description]作为第3列,systemprop0.[lastUpdateTime]作为第4列,systemprop0.[creationTime]作为第5列,来自[dbo].[systemprops]systemprop0.]
NHibernate.Loader.Loader.DoList(ISessionImplementor会话,QueryParameters QueryParameters)+213
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor会话,QueryParameters QueryParameters)+18
NHibernate.Loader.Loader.List(ISessionImplementor会话,QueryParameters QueryParameters,ISet`1查询空间,IType[]结果类型)+79
NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor会话,QueryParameters QueryParameters)+51
NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor会话,QueryParameters QueryParameters)+231
NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters QueryParameters,ISessionImplementor会话,IList结果)+369
NHibernate.Impl.SessionImpl.List(字符串查询、QueryParameters QueryParameters、IList结果)+317
NHibernate.Impl.SessionImpl.List(字符串查询,QueryParameters参数)+282
NHibernate.Impl.QueryImpl.List()+163
C:\Users\HP\Desktop\our\u project\DATA\querys\Systemprop.cs:37中的DATA.systempropensions.GetSystemprop()
C:\Users\HP\Desktop\our\u project\mvcapapplication7\Controllers\acueilcontroller.Index()中的mvcapapplication7.Controllers.acueilcontroller.Index()
lambda_方法(闭包、控制器基、对象[])+62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,对象[]参数)+17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数)+208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数)+27
System.Web.Mvc.c__显示类15.b__12()+55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter筛选器、ActionExecutingContext预文本、Func`1 continuation)+263
System.Web.Mvc.c__显示类17.b__14()+19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext ControllerContext,IList`1筛选器,ActionDescriptor ActionDescriptor,IDictionary`2参数)+191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext ControllerContext,String actionName)+343
System.Web.Mvc.Controller.ExecuteCore()+116
System.Web.Mvc.ControllerBase.Execute(RequestContext-RequestContext)+97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext RequestContext)+10
System.Web.Mvc.c__显示类b.b__5()+37
System.Web.Mvc.Async.c__显示类1.b__0()+21
System.Web.Mvc.Async.c_uuudisplayClass8`1.b_uuu7(IAsyncResult)+12
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+62
System.Web.Mvc.c_uuudisplayClasse.b_uuud()+50
System.Web.Mvc.SecurityUtil.b___0(操作f)+7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(操作)+22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+60
System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+8841105
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+184
有什么办法可以解决这个问题吗?从映射文档中取出所有括号和dbo
。只需使用ta即可
[MySqlException (0x80004005): Erreur de syntaxe près de '[propertyID] as column1_19_, systemprop0_.[value] as column2_19_, systemprop0_.[' à la ligne 1]
MySql.Data.MySqlClient.MySqlStream.ReadPacket() +277
MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId) +73
MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId) +20
MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) +100
MySql.Data.MySqlClient.MySqlDataReader.NextResult() +742
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +1620
MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +4
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +12
NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) +292
NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) +244
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +186
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +129
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +116
[GenericADOException: could not execute query
[ select systemprop0_.[propertyID] as column1_19_, systemprop0_.[value] as column2_19_, systemprop0_.[description] as column3_19_, systemprop0_.[lastUpdateTime] as column4_19_, systemprop0_.[creationTime] as column5_19_ from [dbo].[systemprops] systemprop0_ ]
[SQL: select systemprop0_.[propertyID] as column1_19_, systemprop0_.[value] as column2_19_, systemprop0_.[description] as column3_19_, systemprop0_.[lastUpdateTime] as column4_19_, systemprop0_.[creationTime] as column5_19_ from [dbo].[systemprops] systemprop0_]]
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +213
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +18
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) +79
NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) +51
NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) +231
NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) +369
NHibernate.Impl.SessionImpl.List(String query, QueryParameters queryParameters, IList results) +317
NHibernate.Impl.SessionImpl.List(String query, QueryParameters parameters) +282
NHibernate.Impl.QueryImpl.List() +163
DATA.SystempropExtensions.GetSystemprop() in C:\Users\HP\Desktop\our_project\DATA\Queries\Systemprop.cs:37
MvcApplication7.Controllers.AccueilController.Index() in C:\Users\HP\Desktop\our_project\MvcApplication7\Controllers\AccueilController.cs:16
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841105
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184