Nhibernate 在SharpArchitecture中使用Npgsql时出现的问题
在SharpArchitecture中使用Npgsql时,是否有人可以帮助我。我很沮丧。我使用了Postgresql 8.4、Npgsql 2.0.11、SharpArchitecture 2.0.0.0和visual studio 2010 我的示例项目名为“success” 1) 我在每个项目中都引用了Npgsql驱动程序,并按如下方式配置了我的NHibernate.config,我觉得没有问题:Nhibernate 在SharpArchitecture中使用Npgsql时出现的问题,nhibernate,postgresql,npgsql,sharp-architecture,Nhibernate,Postgresql,Npgsql,Sharp Architecture,在SharpArchitecture中使用Npgsql时,是否有人可以帮助我。我很沮丧。我使用了Postgresql 8.4、Npgsql 2.0.11、SharpArchitecture 2.0.0.0和visual studio 2010 我的示例项目名为“success” 1) 我在每个项目中都引用了Npgsql驱动程序,并按如下方式配置了我的NHibernate.config,我觉得没有问题: <property name="connection.provider">NHib
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
<property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
<property name="connection.connection_string">
Server=localhost;Database=***;Encoding=UNICODE;User ID=***;Password=***;
</property>
6) 我创建了视图,到目前为止还可以,但在最后一步,项目显示错误如下。但是,将项目更改为SQLServer2005平台时没有问题。
错误出现在Global.asax.cs:
...
private void InitialiseNHibernateSessions()
{
NHibernateSession.ConfigurationCache = new NHibernateConfigurationFileCache();
//the follow line codes make error when using Npgsql, but no error when using SQL Server 2005
NHibernateSession.Init(
this.webSessionStorage,
new[] { Server.MapPath("~/bin/success.Infrastructure.dll") },
new AutoPersistenceModelGenerator().Generate(),
Server.MapPath("~/NHibernate.config"));
}
...
错误详细信息如下所示:
...
public AutoPersistenceModel Generate()
{
var mappings = AutoMap.AssemblyOf<studentMap>(new AutomappingConfiguration())
.UseOverridesFromAssemblyOf<studentMap>() //alter AutoMapping Assembly
.OverrideAll(map => { map.IgnoreProperty("Id"); }) // ignore id property, and the program recognize the "sno" as the PK, test OK
...
...
public ActionResult Index()
{
var students = this.studentRepository.GetAll();
return View(students);
}
private readonly StudentRepository studentRepository;
public StudentsController(StudentRepository studentRepository)
{
this.studentRepository = studentRepository;
}
[Transaction]
[HttpGet]
public ActionResult CreateOrUpdate(string sno)
{
student s = studentRepository.GetStudentFromSno(sno);
return View(s);
}
[Transaction]
[ValidateAntiForgeryToken]
[HttpPost]
public ActionResult CreateOrUpdate(student s)
{
if (ModelState.IsValid && s.IsValid())
{
studentRepository.SaveOrUpdate(s);
return this.RedirectToAction("Index");
}
return View(s);
}
[Transaction]
[ValidateAntiForgeryToken]
[HttpPost]
public ActionResult Delete(string sno)
{
var s = studentRepository.GetStudentFromSno(sno);
if (s == null)
return HttpNotFound();
studentRepository.Delete(s);
return this.RedirectToAction("Index");
}
...
System.NotSupportedException was unhandled by user code
Message=Specified method is not supported.
Source=Npgsql
StackTrace:
at Npgsql.NpgsqlConnection.GetSchema(String collectionName, String[] restrictions) in C:\projects\Npgsql2\src\Npgsql\NpgsqlConnection.cs:line 970
at Npgsql.NpgsqlConnection.GetSchema(String collectionName) in C:\projects\Npgsql2\src\Npgsql\NpgsqlConnection.cs:line 946
at NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetReservedWords()
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
InnerException:
请帮帮我!由于缺乏最后的努力,我觉得没有成功。我很沮丧 你看过吗
将“hbm2ddl.keywords
”、“none
”添加到Nhibernate.config
中,看看这是否解决了您的问题 你看过吗
将“hbm2ddl.keywords
”、“none
”添加到Nhibernate.config
中,看看这是否解决了您的问题
...
private void InitialiseNHibernateSessions()
{
NHibernateSession.ConfigurationCache = new NHibernateConfigurationFileCache();
//the follow line codes make error when using Npgsql, but no error when using SQL Server 2005
NHibernateSession.Init(
this.webSessionStorage,
new[] { Server.MapPath("~/bin/success.Infrastructure.dll") },
new AutoPersistenceModelGenerator().Generate(),
Server.MapPath("~/NHibernate.config"));
}
...
System.NotSupportedException was unhandled by user code
Message=Specified method is not supported.
Source=Npgsql
StackTrace:
at Npgsql.NpgsqlConnection.GetSchema(String collectionName, String[] restrictions) in C:\projects\Npgsql2\src\Npgsql\NpgsqlConnection.cs:line 970
at Npgsql.NpgsqlConnection.GetSchema(String collectionName) in C:\projects\Npgsql2\src\Npgsql\NpgsqlConnection.cs:line 946
at NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetReservedWords()
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
InnerException: