使用 SQLite 在 Fluent NHibernate 中使用 SchemaExport 的外键
我正在尝试创建一个简单的数据库应用程序,它使用 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)
)
Is it possible for SchemaExport
使用 SQLite 数据库时生成外键?
谢谢。
I am attempting to create a simple database application which keeps track of loans of various types of equipment using Fluent NHibernate and SQLite. However, when I try to generate the database structure with SchemaExport
for use in unit testing, foreign keys for one-to-many relationships aren't created.
Here is my Equipment
entity:
public virtual int Id { get; set; }
public virtual EquipmentType Type { get; set; }
public virtual int StockId { get; set; }
And here are my mappings for Equipment
:
Id(x => x.Id);
References(x => x.Type);
Map(x => x.StockId);
The SQL is generated correctly, except for the lack of foreign keys:
create table "Equipment" (
Id integer,
StockId INTEGER,
Type_id INTEGER,
primary key (Id)
)
Is it possible for SchemaExport
to generate foreign keys when using an SQLite database?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题。
SQLite 最初不支持外键(3.6.19 中引入的功能),因此 NHibernate SQLiteDialect 实现不知道外键。
由于SQLite不支持通过ALTER TABLE添加约束,只能通过CREATE TABLE参数添加约束,因此不使用NHibernate默认的外键创建。
NHJIRA 上记录了一个事件 https://nhibernate.jira.com/browse/NH-2200
I hit the same problem.
SQLite didn't initially support foreign keys(feature introduced in 3.6.19) so the NHibernate SQLiteDialect implementation doesn't know about foreign keys.
As SQLite doesn't support adding constraints through ALTER TABLE, only through CREATE TABLE parameters, the default foreign key creation of NHibernate is not used.
There's an incident logged on NHJIRA https://nhibernate.jira.com/browse/NH-2200