Sqlite外键与实体框架

时间:2019-03-16 07:58:18

标签: c# entity-framework sqlite

我是第一次尝试使用sqlite + EF。我在SqLite上具有以下简单的主从模型。

CREATE TABLE IF NOT EXISTS VoronoiDiagram
(
    ID integer PRIMARY KEY  AUTOINCREMENT,
    InteriorCells integer,
    DateCreated text,
    DateProcessed text
)

CREATE TABLE IF NOT EXISTS VoronoiCell
(
    ID integer PRIMARY KEY AUTOINCREMENT,
    IsProcessed integer,
    DateCreated text,
    DateProcessed text,
    VoronoiDiagram_ID integer,

    FOREIGN KEY([VoronoiDiagram_ID]) REFERENCES VoronoiDiagram([ID])
)

现在,我有了这样的OnModelCreating方法:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    //var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<MyContext>(modelBuilder);
    //Database.SetInitializer(sqliteConnectionInitializer);

    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

    base.OnModelCreating(modelBuilder);

    modelBuilder.Entity<VoronoiDiagram>()
             .HasKey(s => s.ID)
            .HasMany<VoronoiCell>(c => c.VoronoiCells)
            .WithMany();
    modelBuilder.Entity<VoronoiCell>()
            .HasKey(x => x.ID)
            .HasRequired(c => c.VoronoiDiOnMagram);
}

但是每次我尝试添加带有VoronoiDiagram列表的VoronoiCells实体时,代码都会引发以下异常:

  

SQL逻辑错误:表VoronoiCell没有名为VoronoiDiagram_ID1的列

我也不知道它指的是哪个领域,因为我只有一个叫VoronoiDiagram_ID的地方。任何帮助,将不胜感激。我正在使用System.Data.SQLite + EF 6.0的1.0.110.1版

0 个答案:

没有答案