Another entry in the scripting API samples, you will find an overview of getting started with the API here.
This weeks entry demonstrates the general pattern for scripting smaller chunks of SQL based on a single table, in this case a INSERT statement for each row in the table.
using (IRepository repository = new DBRepository(@”Data Source=C:Northwind.sdf”))
Generator generator = new Generator(repository, null);
foreach (var tableName in repository.GetAllTableNames())
For SQL Server Compact 4.0, the scripting library is now available on NuGet, making it even easier to get started. https://nuget.org/packages/ErikEJ.SqlCeScripting