Enabling foreign keys only works for the entire life of the database connection. By default, the ObjectContext will open the connection and close it whenever you interact with the database if you called SaveChanges() , ExecuteStoreCommand() or otherwise. If you do not want this behavior, you need to manually open the connection and ideally close it when you are done with the ObjectContext .
I prefer to include foreign keys in the connection string, so I do not need to worry about one of the above.
For example, in your app.config file you will have something like this (look for foreign keys=True near the end of the connectionString attribute):
<configuration> <connectionStrings> <add name="DataBaseEntity" connectionString="metadata=res://*/m.csdl|res://*/m.ssdl|res://*/m.msl;provider=System.Data.SQLite;provider connection string="data source=C:\foo.db;foreign keys=True"" providerName="System.Data.EntityClient" /> </connectionStrings> </configuration>
I think this should work with your ADO.Net provider, but I cannot do promises. If you upgrade to the latest version available on the SQLite website , you will increase your chances that it will work properly.
user610650
source share