ErikEJ / SqlCeToolbox

SQLite & SQL Server Compact Toolbox extension for Visual Studio, SSMS (and stand alone)
Other
838 stars 175 forks source link

Trouble generating EDMX from Sql Compact SDF 3.5 #325

Closed hotsdogs closed 7 years ago

hotsdogs commented 7 years ago

I am trying to generate an edmx for a SQL Compact 3.5 SDF file. I created the SDF file in Visual Studio 2010 using the Local Database Cache wizard in order to create the .SYNC file to sync the date to our SQL 2008 server . The cache created with the sdf table based on the tables in the SQL 2008 database. Then I open the same project to Visual Studio 2015 to generate the EDMX using the SQL Lite tool box. The only option I can find is to generate the file using the Entity Data Model (code first from database) to current project. This is requiring the Entity Framework Reverse POCO Code First Generator. I have installed that as well. I also have SQL Compact 3.5 installed.

The file it is generating is the Database.tt, and the two POCO files. However, not all the functions are being implemented from the interface created in the Database.CS file specifically, SaveChangesAsync, FindAsync. As well the namespace IDbAsyncEnumerator and IDbAsyncQueryProvider are not being found in System.Data.Entity.Infrastructure.

I am also getting the error DatabaseGeneratedOption exists in both EntityFramework 6.0.0.0 and System.ComponentModel.DataAnnotations 4.0.0.0.

I have also tried registering the DDEX for Sql Compact 3.5 provider but when viewing the about it always reads no.

I used a previous version of the tool box to create the EDMX with no problems but this latest version is not working the same way and I am not sure what to do differently.

Toolbox version: 4.7.87.0 Database engine: Sql Compact 3.5 Visual Studio version: 2015 and 2010.

ErikEJ commented 7 years ago

Thanks for your detailed error report!

There are a few issues at play here: 1: I have given up supporting the 3.5 DDEX provider - it was too flaky and broken in many scenarios.

2: I recommend using EF Reverse POCO to avoid EDMX files all together, yes.

3: Glad you got the EF POCO template to work with SQL CE 3.5! Let's iron out the remaining issues:

a: What version of the template do you use (see the top of the database.tt file) - latest is v2.29.1

b: It sounds like you have installed the .NET 4.0 version of the EF provider in your project, but that you really want to target .NET 4.5, is that correct? If that is the case, uninstall the EntityFramework and the EntityFramwork,SqlServerCompact.Legacy NuGet packages from you project, and re-install to activate the 4.5 version.

(Or do it the other way around, so that the installed EF version matches the target framework version of your project)

Please let me know if that fixes the compilation errors - if not, I would like to have a look at your project, if possible.

hotsdogs commented 7 years ago

The version of the template for the reverse POCO generator is 2.29.1.

I figured the issue was something to do with versioning between some of the entity framework and that turned out to be right. I decided to start with a new project as .Net 4.5 and once all was built everything seems to work fine. I usually have to switch the project to .Net 4.0 to be able to open it in Visual Studio 2010 to create the SYNC context.

The only have two issues now. There is a Date field in the main database and the SYNC wizard and/or reverse POCO generator created a string field in the database context. I suspect the SDF cannot handle a Date only field.

Also I have now is some things to do with the SYNC file built to sync the data which I created with Visual studio 2010 and the local cache file. I probably need to get away from doing that since Microsoft not longer supports it but it is quite convenient and I really do not like the other way where the sync framework builds all the other tables and stored procedures in the database.

Thanks for replying so quickly.

ErikEJ commented 7 years ago

You are welcome, and yes, the SQL Server DATE type is not supported by SQL Server Compact