休眠和sqlite映射 [英] nHibernate & sqlite mappings

查看:104
本文介绍了休眠和sqlite映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用sqlite设置nHibernate时遇到了实际问题.

I'm having real problems with setting up nHibernate with sqlite.

这是hibernate.cfg.xml文件:

Here is the hibernate.cfg.xml file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.SQLite20Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
    <property name="connection.connection_string">Data Source=books.db;Version=3</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    <property name="query.substitutions">true=1, false=0</property>

    <property name="show_sql">true</property>
    <property name="format_sql">true</property>


  </session-factory>
</hibernate-configuration>

这是(简化的)映射文件:

and here is the (simplified) mapping file:

 <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly ="DataAccess" namespace="DataAccess.DOM">
  <class name="Book" table="book">
    <id name="id" type="integer" unsaved-value="null">
      <generator class="increment"/>
    </id>

    <property name="isbn" type="string" length="25"/>
    <property name="author" type="string" length="100"/>

  </class>
</hibernate-mapping>

表格:

create table book(
  id INTEGER primary key,
  author TEXT,
  isbn TEXT,
);

我得到了错误: 无法编译映射文档:DataAccess.DOM.Book.hbm.xml"

I get the error: "Could not compile the mapping document: DataAccess.DOM.Book.hbm.xml"

我正在VS2008的Vista 32位系统上进行开发.

I'm developing in VS2008 on Vista 32bit.

我已经添加了System.Data.SQlite程序集,并设置为复制本地.

I've added the System.Data.SQlite assembly and set to copy local.

有什么建议吗?

推荐答案

我很久以前就解决了这个问题,现在已经不记得我做了什么了:o(

I fixed this ages ago, and now can't remember exactly what I did :o(

但是,看一下代码:我注意到对映射文件的这一更改,我将Id的标记从整数更改为Int32,并将生成器类从增量更改为了本机:

However, looking at the code: I notice this change to the mapping file, I changed the tag for the Id from integer to Int32 and the generator class from increment to native:

<id name="Id" type="Int32" unsaved-value="0">
  <generator class="native"/>
</id>

这篇关于休眠和sqlite映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆