0

这是我最初的 SQLite 数据库

CREATE TABLE [Categories] (
  [ParentId] INT, 
  [Name] VARCHAR(100));

CREATE TABLE [Fees] (
  [CategoryId] INT, 
  [Name] VARCHAR(100), 
  [Value] VARCHAR(50), 
  [Info] VARCHAR(200));

CREATE TABLE [Markups] (
  [CategoryId] INT, 
  [UpTo] MONEY, 
  [Value] VARCHAR(50), 
  [Info] VARCHAR(200));

如果我运行DbMetal /provider:Sqlite /conn "Data Source=bms4.db3" /dbml:Model.dbml,它将成功创建 dbml 文件。

但是如果我添加一个外键,这样

CREATE TABLE [Fees] (
  [CategoryId] INT CONSTRAINT [fk_fees_categories] REFERENCES [Categories]([rowid]), 
  [Name] VARCHAR(100), 
  [Value] VARCHAR(50), 
  [Info] VARCHAR(200));

运行相同的命令

DbMetal /provider:Sqlite /conn "Data Source=bms4.db3" /dbml:Model.dbml

会给出这个错误:

>>> Reading schema from SQLite database
DbMetal: The given key was not present in the dictionary.

如何将外键关系引入 DBML?

4

1 回答 1

0

根据约束中的唯一键检查外键。您尚未声明主键或唯一键,因此您需要先声明(最好确保每个表都有一个主键)

于 2012-11-09T00:11:33.290 回答