A couple of days ago I had to migrate from SQL Server 2012 to SQL Server CE 4. I tried to do it manually, but gave up very soon.
Google helps again, after some research I found a couple of open source C# projects which do the work. Non of them worked for me, but I still took some pieces of code and wrote my own converter.
To avoid version conflicts I post it as a C# class. To make it work you have to create a VS solution (Console Application in my case) and include references to those assemblies:
Microsoft.SqlServer.Smo.dll, Can be found here: C:\Program Files\Microsoft SQL Server\110\SDK\Assemblies
Migrator creates new SQL CE4 database and generates .sql script of database.
Hope it will help someone.