ASP.NET MVC 4 EF5 with MySQL

前端 未结 3 847
半阙折子戏
半阙折子戏 2020-12-07 16:52

So I\'ve just picked up VS2012 and I want to start an ASP.NET MVC 4 app with EF5.

My host does not have MSSQL so I have to use MySQL.

How do I tell my app th

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 17:31

    You need to setup your config with a connection string, DbProviderFactory and a custom DatabaseInitializer for MySql Connector 6.5.4. I have detailed the full step for getting EF5 and MySql to play, including code for the initializers on my blog. If you require ASP.Net membership provider solution it been asked before: ASP.NET Membership/Role providers for MySQL? I will post the solution here also for a complete EF5 MySql solution.

    The MySql connector does not currently support EF 5 migration and ASP.NET only supports SimpleMembership (MVC4 default) on MS SQL not MySql. The solution below is for Code First.

    The steps are:

    1. Grab EF 5 from NuGet
    2. Grab MySql.Data and MySql.Data.Entity from NuGet (6.5.4) or MySql (6.6.4)
    3. Configure a MySql Data Provider
    4. Configure a MySql Connection String
    5. Create a Custom MySql Database Initializer
    6. Configure the Custom MySql Database Initializer
    7. Configure ASP.NET membership if you require it

    DbProvider

    
     
      
      
     
    
    

    Connection String

    
      
    
    

    Database Initializer

    If you are using MySql connector from NuGet (6.5.4) then a custom initializer is required. Code available at http://brice-lambson.blogspot.se/2012/05/using-entity-framework-code-first-with.html or at http://www.nsilverbullet.net/2012/11/07/6-steps-to-get-entity-framework-5-working-with-mysql-5-5/

    Then add this to configuration

    
      

    ASP.NET Membership

    
      
        
        
      
    
    

    Get the AccountController and Views working:

    1. Delete the MVC 4 AccountController, AccountModels, Account view folder and _LoginPartial shared view
    2. Create a new MVC 3 web application
    3. Copy the MVC 3 AccountController, AccountModels, Account view folder and _LogOnPartial shared view into your MVC 4 application
    4. Replace @Html.Partial(“_LoginPartial”) in the shared _Layout view with @Html.Partial(“_LogOnPartial”)

提交回复
热议问题