none
EntityFramework Change Database SqlCompact -SqlServer without recompile RRS feed

  • Question

  • Hi

    I want to change the Database on which the entity Framework connects without recompiling my project. Within the same database type, everything works fine and i only have to change the connectionstring.

    But when changing between SqlCompact and SqlServer this won't work because there are differences in the Schema files.

    Currently I've one Project with the EDMX Files, One with the DbContext and DBSet (including the generated entitied) and multiple assemblies which are using the DBContext and DbSet to connect to the databases.

    What is the best way to make the database (and also dbType including Schemas) changeable without needing a recompile ?

    Monday, January 9, 2012 1:57 PM

Answers

  • Hi Gentlehag,

    According to your description, the database structures are same for SQL Server and SQL CE, you want to use one Edxm file for the two database, right? The difference between SQL CE and SQL Server is here:

    SQL CE:

     <Schema Namespace="Model.Store" Alias="Self" Provider="System.Data.SqlServerCe.4.0" ProviderManifestToken="4.0" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
    

    SQL Server:

     <Schema Namespace="Model2.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
    

    // right click the edmx file --->open with XML --->edit this line.

    You also need to change the connection string in your config file.

    If in EF4.1 Code First, you just need to change the connectionstring in DbContext's constructor.

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Gentlehag Tuesday, January 10, 2012 2:27 PM
    Tuesday, January 10, 2012 7:50 AM
    Moderator

All replies

  • Hi Gentlehag,

    According to your description, the database structures are same for SQL Server and SQL CE, you want to use one Edxm file for the two database, right? The difference between SQL CE and SQL Server is here:

    SQL CE:

     <Schema Namespace="Model.Store" Alias="Self" Provider="System.Data.SqlServerCe.4.0" ProviderManifestToken="4.0" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
    

    SQL Server:

     <Schema Namespace="Model2.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
    

    // right click the edmx file --->open with XML --->edit this line.

    You also need to change the connection string in your config file.

    If in EF4.1 Code First, you just need to change the connectionstring in DbContext's constructor.

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Gentlehag Tuesday, January 10, 2012 2:27 PM
    Tuesday, January 10, 2012 7:50 AM
    Moderator
  • Thx for your reply.

    Yes the structures are the same.

     

    But the edmx is part of the assembly, isn't it  ?

    How can I use an external edmx file ?

    Do you have an shot example?

    Or do I have to compile Two assemblies with different EDMX, CSDL,... ?

    And whats the syntax to point to an external assembly with the CSDL,SSL,MSL ?


    • Edited by Gentlehag Tuesday, January 10, 2012 8:39 AM
    Tuesday, January 10, 2012 8:16 AM