在Fluent NHibernate中使用SQLite的SchemaExport的外键 [英] Foreign Keys with SchemaExport in Fluent NHibernate using SQLite
问题描述
SchemaExport
生成用于单元测试的数据库结构时,不会创建用于一对多关系的外键。 这是我的 Equipment 实体:
public virtual int Id {get;组; }
public virtual设备类型类型{get;组; }
public virtual int StockId {get;组; }
这里是我的 Equipment
:
Id(x => x.Id);
参考文献(x => x.Type);
Map(x => x.StockId);
SQL正确生成,除了缺少外键:
create tableEquipment(
Id integer,
StockId INTEGER,
Type_id INTEGER,
主键(Id)
)
对 SchemaExport
在使用SQLite数据库时生成外键?
谢谢。
SQLite最初并不支持外键(在3.6.19中引入的功能),所以NHibernate的SQLiteDialect实现不会因为SQLite不支持通过ALTER TABLE添加约束,所以只能通过CREATE TABLE参数,不使用NHibernate的默认外键创建。
有个事件记录在NHJIRA https://nhibernate.jira.com/browse/NH-2200
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.
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
这篇关于在Fluent NHibernate中使用SQLite的SchemaExport的外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!