This is for a new project which will start on the desktop with the option to scale to multiple users on SQL Server 2008 R2 or SQL Server 2012
I’m looking for some real world experience, tips, gotchas etc.
UPDATE – Ideally would prefer to switch in runtime via a config entry.
UPDATE 2 – Are there any pattern(s) which can be used here?
UPDATE 3 – the SQL SERVER 2008 db schema is already in prod use, so cannot start with ssce model code first and progress from there
The theory
EDMX
In case of EDMX you need at least two SSDL files. One for SQL server and one for SQL Server CE. The reason is that SSDL file describes database including database types. Some types in SQL Server CE are different. For example SQL server CE doesn’t support
NVARCHAR(max)and you must useNTEXTinstead. SSDL also contains information about provider manifest so even if your column types and names are exactly same you still need to SSDLs to differ provider manifests.If your tables and names in both databases will be same you can use same MSL (CSDL must be the same). Working with two SSDLs is much harder because it either means two EDMXs and some manual synchronization of changes or single EDMX and some script which will extract second SSDL or maintaining whole mapping manually in XML files. Entity framework VS designer is not prepared for this type of usage.
Code-first
Code first provides much more simplified situation because you don’t have to deal with SSDL. SSDL is created automatically when your application starts based on provider defined in connection string and mapping defined in your model.
Even code first can have problems when it comes to different data types in SQL Server and SQL Server CE. As and example we can again use large strings.
The practice
The theory says it is possible. The practice says it can be much more challenging. SQL Server and SQL Server CE are different database servers with different features and performance. SQL Server provides much more features and some of these features will not work on SQL Server CE (views, sql procedures) at all (you mentioned you already have schema for SQL Server) or will be much slower. Once you meet this limitations you will either have to branch your development for separate support on SQL Server and SQL Server CE or you will have to make compromises.