我是第一次尝试使用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版