How do I allow the EF4 CodeFirst database initializer to run under development, but not run in production

后端 未结 5 651
有刺的猬
有刺的猬 2021-01-01 07:06

I am attempting to deploy my first alpha version of a system online for a few people to start using. On development I make heavy use of the DropCreateDatabaseOnModelC

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 07:32

    As @Johann says, the ConditionalAttribute is probably the cleanes solution here:

    [Conditional("DEBUG")]
    private void InitializeDb()
    {
        // Initializer code here
        // DropCreateDatabaseOnModelChange
    }
    

    and in Global.asax:

    public void Application_Start // or wherever it is you're initializing
    {
        // This will only be called if the DEBUG constant is defined
        InitializeDb();
    }
    

提交回复
热议问题