Change Entity framework database schema at runtime

前端 未结 8 2667
花落未央
花落未央 2021-02-20 13:02

In most asp.net applications you can change the database store by modifing the connectionstring at runtime. i.e I can change from using a test database to a production database

8条回答
  •  庸人自扰
    2021-02-20 13:36

    Sorry its not a robust answer but I found this project on codeplex ( as well as this question ) while googling around for a similar problem:

    http://efmodeladapter.codeplex.com/

    The features include:

    • Run-time adjustment of model schema, including:
    • Adjusting data-level table prefixes or suffixes
    • Adjusting the owner of database objects

    Some code from the docs:

    public partial class MyObjectContext : BrandonHaynes.ModelAdapter.EntityFramework.AdaptingObjectContext
    {
            public MyObjectContext() 
            : base(myConnectionString, 
            new ConnectionAdapter(
                new TablePrefixModelAdapter("Prefix", 
                    new TableSuffixModelAdapter("Suffix")), 
            System.Reflection.Assembly.GetCallingAssembly()))
        {
        ...
        }
    

    }

    Looks like its exactly what your looking for.

提交回复
热议问题