简体   繁体   中英

C# - Entity Framework enable FK with SQLite

I'm working in a Entity Framework + SQLite app, and i don't know how activate PRAGMA foreign_keys = 1 in the Model for C# application.

Here my model (My_model.Context.cs)

using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

    public partial class My_Model : DbContext
{
    public My_Model()
       : base("name=My_Model")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public virtual DbSet<My_TABLE1> My_TABLE1 { get; set; }
    public virtual DbSet<My_TABLE2> My_TABLE2 { get; set; }
    public virtual DbSet<My_TABLE3> My_TABLE3 { get; set; }
    public virtual DbSet<My_TABLE4> My_TABLE4 { get; set; }
}

Any idea?

I have tried modify App.conf doesn't works. I have found many examples but no works for me.

在您的App.Config文件中,将“ foreign keys = true”添加到连接字符串,如下所示:

data source=c:\wherever\whatever.sqlite;DateTimeFormat=InvariantCulture;foreign keys=true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM