2012-05-02 21 views
1

SharpArchitectureでNpgsqlを使用するときに助けてくれる人がいますか? Postgresql 8.4、Npgsql 2.0.11、SharpArchitecture 2.0.0.0、Visual Studio 2010を使用しました。SharpArchitectureでNpgsqlを使用すると問題が発生する

"success"という名前のサンプルプロジェクト。

<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> 

2)以下のように私のデータベース・ドメイン・ファイル、テーブル名の学生:

1)私はすべてのプロジェクトにNpgsqlのドライバを参照して、以下のように私のNHibernate.configをConfigが、私は問題はありません感じました(SNO、SNA​​ME、セージ)、SNOはPKと入力した文字列である:非Id列テーブルを使用するために)

//student.cs 
using System.Collections.Generic; 
using SharpArch.Domain.DomainModel; 
namespace success.Domain { 
public class student : Entity 
{ 
     public student() { } 
     public virtual string sno { get; set; } 
     public virtual System.Nullable<int> sage { get; set; } 
     public virtual string sname { get; set; } 
    } 
} 

//studentMap.cs 
using FluentNHibernate.Automapping.Alterations; 
namespace success.Domain { 
public class studentMap : IAutoMappingOverride<student> 
{ 
    public void Override(FluentNHibernate.Automapping.AutoMapping<student> mapping) 
    { 
     mapping. Table("student"); 
     mapping.LazyLoad(); 
     mapping.Id(x => x.sno).GeneratedBy.Assigned().Column("sno"); 
    //I don't used Id but sno as the PK, and sno is typed string. 
     mapping.Map(x => x.sage).Column("sage"); 
     mapping.Map(x => x.sname).Column("sname"); 
    } 
} 
} 

3以下のように、私は、デフォルトMyEntity1.cs、および修飾AutoPersistenceModelGenerator.csを削除します

... 
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 
... 

4)Tasksプロジェクトでは、 "sno"でレコードを取得するために、インタフェースIStudentRepository.csとクラスStudentRepository.csを作成し、NHibernateRepositoryを変更しました。

//IStudentRepository.cs 
using success.Domain; 
using SharpArch.NHibernate.Contracts.Repositories; 
namespace success.Tasks.IRepository 
{ 
public interface IStudentRepository:INHibernateRepository<student> 
{ 
    student GetStudentFromSno(string sno); 
} 
} 

//StudentRepository.cs 
using SharpArch.NHibernate; 
using success.Domain; 
using success.Tasks.IRepository; 
using NHibernate; 
using NHibernate.Criterion; 
namespace success.Tasks.Repository 
{ 
public class StudentRepository:NHibernateRepository<student>,IStudentRepository 
{ 
    public student GetStudentFromSno(string sno) //define a new method to fatch record by sno 
    { 
     ICriteria criteria = Session.CreateCriteria<student>()  
      .Add(Expression.Eq("sno", sno));  
     return criteria.UniqueResult() as student; 
    } 
} 
} 

MVCプロジェクトでは、StudentController.cs、代わりにNHibernateRepositoryの使用StudentRepository、以下のようにいくつかのキー・コードを作成5):私は、ビューを作成し、それが今まですべてです

... 
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"); 
    } 
... 

6)が、最後のステップでは、プロジェクトのエラーが続きます。ただし、プロジェクトをSQL Server 2005プラットフォームに変更しても問題はありません。 エラーが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")); 
} 
... 

エラーの詳細:

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: 

が私を助けてください!私は最終的な努力の欠如のために成功に足りないと感じました。私はイライラしています!

答えて

1

あなたはthisを見ましたか?

Nhibernate.configに "hbm2ddl.keywords"、 "none"を追加して問題が解決するかどうか確認してください。

関連する問題