I am trying to use EF Code First with my WPF application, the idea is to create SqlCe Db in AppData / MyApp (if it is not) and use it with EF Code First.
It currently gives an error when I try to read data from the database that it was supposed to create, but when I checked the db context object, I saw that it was trying to create it in SqlExpress.
First of all, how can I configure it to work with CE instead of SqlExpress and set the file location?
I tried to change the connection string in app.config, but could not get it to work (he did not create the sdf file), and I am also not sure how to set the connection string path to the AppData folder, as in User (not fixed).
Never worked with SqlCe or EF code. First of all, therefore, any help is appreciated and appreciated.
Thanks in advance.
I managed to get it to work after many riots. My app.config has the following:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> </configSections> <connectionStrings> <add name="Database" connectionString="Data Source=Database.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings> <system.data> <DbProviderFactories> <remove invariant="System.Data.SqlServerCe.4.0" /> <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/> </DbProviderFactories> </system.data> </configuration>
Having a DbProviderFactory there will help when it comes to deployment. This will allow users to use SQLCE 4 without starting the installer for it (provided that you provide your own binary, as well as the information here: http://erikej.blogspot.com/2011/02/using-sql-server-compact-40- with.html ).
. EFCodeFirst.SqlServerCompact NuGet : Visual Studio 2010\Projects\MyProject\packages\EFCodeFirst.SqlServerCompact.0.8.8482\Content, - -, :
public static class AppStart_SQLCEEntityFramework { public static void Start() { DbDatabase.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"); // Sets the default database initialization code for working with Sql Server Compact databases // Uncomment this line and replace CONTEXT_NAME with the name of your DbContext if you are // using your DbContext to create and manage your database //DbDatabase.SetInitializer(new CreateCeDatabaseIfNotExists<CONTEXT_NAME>()); } }
, SQLCE WPF. .
, , , . , - , , , , , - SqlCE4, CodeFirst NuGet . NuGet, , , SqlCE4 CodeFirst WPF / WinForms.
, , -, WebActivator. , , WebActivator -- . , NuGet . , - EFCodeFirst.SqlServerCompact, --, .
, , , . , , NuGet. , - , config ..