私はこのこのコードを持っています:
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using base_donnee;
using System.IO;
namespace TrackingUnitSimulator
{
public class connection
{
public ISession session ;
public IList<simulateur> simulateurs = null;
public IList<user> users = null;
public IList<equipment> equipments = null;
public IList<string> jours = null;
public IList<int> conn_1 = null;
public IList<int> recep_1 = null;
public IList<int> envoi_1 = null;
public IList<int> conn_tout = null;
public IList<int> recep_tout = null;
public IList<int> envoi_tout = null;
public IList<Performance> performances = null;
public int[] mesures = new int[100];
public IList<int> nombres = null;
public connection()
{
ISessionFactory factory;
Configuration config = new Configuration();
config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2005Dialect");
config.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver");
config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Data Source=HP-PC\\SQLEXPRESS;Initial Catalog=Simulation;Integrated Security=True;Pooling=False");
config.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
config.AddAssembly("base_donnee");
factory = config.BuildSessionFactory();
try
{
session = factory.OpenSession();
try
{
simulateurs = session.CreateQuery(@"select e from simulateur e ordred by e.Date").List<simulateur>();
users = session.CreateQuery(@"select e from user e ").List<user>();
}
catch (Exception ex) { File.AppendAllText(@"C:\Users\HP\Desktop\test.txt",ex.ToString());}
equipments = session.CreateQuery(@"select e from equipment e ").List<equipment>();
performances = session.CreateQuery(@"select e from Performance e ").List<Performance>();
jours = session.CreateQuery(@"select distinct e.Date from simulateur e ordred by e.Date").List<string>();
nombres = session.CreateQuery(@"select e.Nombre_simulateur from simulateur e ordred by e.Date").List<int>();
conn_1 = session.CreateQuery(@"select e.temps_connection from simulateur e where e.Nombre_simulateur = 1 ").List<int>();
recep_1 = session.CreateQuery(@"select e.temps_reception from simulateur e where e.Nombre_simulateur = 1 ").List<int>();
envoi_1 = session.CreateQuery(@"select e.temps_envoi from simulateur e where e.Nombre_simulateur = 1 ").List<int>();
conn_tout = session.CreateQuery(@"select e.temps_connection from simulateur e ").List<int>();
recep_tout = session.CreateQuery(@"select e.temps_reception from simulateur e ").List<int>();
envoi_tout = session.CreateQuery(@"select e.temps_envoi from simulateur e ").List<int>();
int i = 0;
foreach (string j in jours) {
IQuery query = session.CreateQuery(@"select e from simulateur e where e.Date=:j ");
query.SetString("j", j);
IList<simulateur> med = query.List<simulateur>();
mesures[i] = med.Count;
i++;
}
}
catch
{
session.Close();
}
}
public ISession getSession(){
return session;
}
}
}
およびクラス user.cs :
using System;
using System.Collections.Generic;
using System.Text;
namespace base_donnee
{
public class user
{
public virtual string login { get; set; }
public virtual string password { get; set; }
public virtual string name { get; set; }
public virtual int age { get; set; }
public virtual string location { get; set; }
}
}
およびクラス user.hbm.xml:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="base_donnee">
<class name="base_donnee.user, base_donnee" table="user">
<id name="login" type="string"></id>
<property name="password" type="string" />
<property name="age" type="int" />
<property name="location" type="string" />
<property name="name" type="string" />
</class>
</hibernate-mapping>
私の問題は、例外が表示されることです。 ] [SQL: ユーザー user0_ から、user0_.login を login3_ として、user0_.password を password3_ として、user0_.age を age3_ として、user0_.location を location3_ として、user0_.name を name3_ として選択する] ---> System.Data.SqlClient.SqlException:キーワード「user」付近の構文が正しくありません。
このエラーを回避するにはどうすればよいですか?そしてなぜテーブルユーザーですか?