Question

I'm facing an issue that many already faced, with a difference: neither the SDF file name, or the path, contains invalid characters. I've even tried with the Northwind.sdf file and Ikeep getting the same issue.

And example of a full path: D:\Sviluppo\dotnet\EnergiaClima\EnergiaClimaWindows\App_Data\Northwind.sdf

The error message:

System.ArgumentException: The modelEntityContainerName parameter 'D:\Sviluppo\dotnet\EnergiaClima\EnergiaClimaWindows\App_Data\NorthwindsdfContext' contains characters that are not valid.
   at System.Data.Entity.Design.EntityModelSchemaGenerator..ctor(EntityContainer storeEntityContainer, String namespaceName, String modelEntityContainerName)
   at Microsoft.DbContextPackage.Handlers.ReverseEngineerCodeFirstHandler.ReverseEngineerCodeFirst(Project project)

This issue is driving me crazy: does the EF Power Tools Beta 3 actually works in VS2010? If not, what's the best (and easier) way to get an Entity Model from a SQLCE4.0 DB (something that is not creating a 3.5 DB and editing XML files, if possible)?

I can't understand why SQLCE4.0 support is so poor.

Was it helpful?

Solution

Now it's a verified issue: http://entityframework.codeplex.com/workitem/898

I wonder how the guys test their library: did they ever tried to use EF5 Code First with a SQL CE database?

Anyway, hopefully it will be solved in EF6.

OTHER TIPS

Assuming that you would like to create an edmx from a SQL Server Compact file, you can use my SQL Server Compact Toolbox extension to create the edmx from any 3.5 or 4.0 file.

This is still occurring on existing file based db's. This will occur in both Sql Server Compact and LocalDb. It has to do with the database name under the server instance. If you attempt to connect to a raw .mdf / .sdf directly from the "Reverse Engineer Code First" connection dialogs before connecting to the same db through code, the DB engine will load the database into the server instance with a name that equals the full path of the db because there is no place to name the database (initial catalog) and has to name the database in order to load it to the sql server instance. Then when EF Reverse Engineer Code First attempts to create a context, it chokes on the backslashes (and probably colon) that exist in the DBName. {note: If you connect after you have already issued some code against the database connection string, the server instance loads the database file with the Initial Catalog you provided (which likely doesn't have special characters) and everything is ok.}

The quick and easy solution is to:

1) shut down Visual Studio to kill your connection to the DB.

2) Start SQL Server Management Studio and connect to "(localDB)\v11.0" {note this is for localDB instance, I don't know what the compact DB instance is.

3) Right click on the database name and select rename to rename the database to your desired initial catalog name instead of the full filename path name.

Maybe EF Reverse Engineer Code First tool should evaluate the DBName and only use everything past the last slash minus the file extension for the DBContext? Especially since most of the connection strings define the initial catalog to the same name as the file name.

Hope this helps someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top