How to create bootstrapper class for Entity Framework 4.3 and SQL Server Compact 4.0

( TL; DR version is the question in bold at the bottom)

When Entity Framework 4.1 Code First was originally released (actually it was CTP5 time) there was a NuGet package named EFCodeFirst

. This can be used in conjunction with another named NuGet package to EFCodeFirst.SqlServerCompact

enable EF to be used with SQL Server Compact 4.0 (SQL Server CE).

Installing the package EFCodeFirst.SqlServerCompact

would create a scaffold or create a "bootstrapper" class named SQLCEEntityFramework.cs

in the folder App_Start

that would configure things like EF Database.DefaultConnectionFactory

and generate "stubs" for other useful methods (initialization, db seeding, etc.) using WebActivator

package

These two packages ( EFCodeFirst

and EFCodeFirst.SqlServerCompact

) is now obsolete and it seems replaced by an equivalent package EntityFramework

and EntityFramework.SqlServerCompact

, and both of them are on version 4.3.1 now

My problem is, using these new packages in a new project, they don't seem to create a "bootstraper" class to set up EF to use SQL Server Compact at runtime. Of course, I can just copy the old version of the class from a previous project, but it would be nice to know that the NuGet package still contains this functionality (which could potentially be updated over time).

Is there a way to get the latest version (4.3.1 at the time of this writing) of the package EFCodeFirst.SqlServerCompact

to create the boottrapper class, SQLCEEntityFramework.cs

either after installation or after the fact (perhaps via the powershell command?)?

UPDATE:
I just noticed that the previous version ofEFCodeFirst.SqlServerCompact

NuGetPackage still has a dependency on the package WebActivator

(which is used by the bootstrapper class), however this dependency was removed from the latest version and one prior to the latest version . It looks like the functionality that generates the bootstrapper class has been removed, but why am I wondering?

+3


source to share


1 answer


In EF 4.1, the only way to do Code First is to create a SQL Server Compact database by convention (that is, without explicitly specifying a connection string) is to set the DefaultConnectionFactory to your code. This is problematic because tools (such as Migrations), which need to know which database are in use, don't know that code is present.)

In EF 4.3, we added the ability to do this in the web.config file. The EntityFramework.SqlServerCompact package takes advantage of this by setting the SQL Conmpact as the default factory connection in your web config. So you don't need to use a WebActivator or code to do this.



You can still use the code method if you want ypu, but keep in mind that things like Migrations may not work correctly and we recommend that you use a config file instead.

+3


source







All Articles