【问题标题】:Foreign Keys with SchemaExport in Fluent NHibernate using SQLite使用 SQLite 在 Fluent NHibernate 中使用 SchemaExport 的外键
【发布时间】:2010-06-16 23:53:08
【问题描述】:

我正在尝试创建一个简单的数据库应用程序,该应用程序使用 Fluent NHibernate 和 SQLite 跟踪各种设备的贷款。但是,当我尝试使用 SchemaExport 生成用于单元测试的数据库结构时,不会创建一对多关系的外键。

这是我的Equipment 实体:

public virtual int Id { get; set; }

public virtual EquipmentType Type { get; set; }

public virtual int StockId { get; set; }

这是我对Equipment 的映射:

Id(x => x.Id);
References(x => x.Type);
Map(x => x.StockId);

SQL 生成正确,只是缺少外键:

create table "Equipment" (
       Id integer,
       StockId INTEGER,
       Type_id INTEGER,
       primary key (Id)
    )

SchemaExport 在使用 SQLite 数据库时是否可以生成外键?

谢谢。

【问题讨论】:

    标签: nhibernate sqlite fluent-nhibernate foreign-keys schemaexport


    【解决方案1】:

    我遇到了同样的问题。

    SQLite 最初不支持外键(3.6.19 中引入的功能),因此 NHibernate SQLiteDialect 实现不知道外键。

    由于SQLite不支持通过ALTER TABLE添加约束,只能通过CREATE TABLE参数,所以不使用NHibernate默认的外键创建。

    在 NHJIRA https://nhibernate.jira.com/browse/NH-2200 上记录了一个事件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多