简体   繁体   English

使用SQLite对NHibernate Postgresql进行单元测试。 序列发生器问题

[英]Unit testing NHibernate Postgresql with SQLite. Sequence generator problem

Can Sqlite NHibernate id generator be made compatible with Postgresql? 可以将Sqlite NHibernate id生成器与Postgresql兼容吗? I'm planning to unit test my NHibernate Postgresql project based on this http://ayende.com/Blog/archive/2009/04/28/nhibernate-unit-testing.aspx 我打算根据这个http://ayende.com/Blog/archive/2009/04/28/nhibernate-unit-testing.aspx对我的NHibernate Postgresql项目进行单元测试。

If there is no compatible id generator, is there a way to signal NHibernate to ignore id generator when it is using different dialect? 如果没有兼容的id生成器,有没有办法让NHibernate在使用不同的方言时忽略id生成器?

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="RuntimeNhibernate" namespace="RuntimeNhibernate" >

  <class name="Blog" table="blog">
    <id name="BlogId" column="blog_id">
        <!-- can this be ignored when using different dialect.. -->
        <generator class="sequence"> 
            <param name="sequence">blog_id_seq</param>
        </generator> 
        <!-- ...can this -->
    </id>


    <property name="AllowsComments" column="allows_comments"/>
    <property name="CreatedAt" column="created_at"/>
    <property name="Subtitle" column="subtitle"/>
    <property name="Title" column="title"/>


  </class>

</hibernate-mapping>  

Error when using Sqlite dialect on Postgresql-specific mapping: 在Postgresql特定的映射上使用Sqlite方言时出错:

NHibernate.MappingException: could not instantiate id generator: sequence ---> 
NHibernate.MappingException: Dialect does not support sequences

我的建议是你使用一个与数据库无关的生成器,比如HiLo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM