How to Use Entity Framework 6.x in Asp.Net 5 (MVC 6)

asp.net-core asp.net-core-mvc c# entity-framework-6

Accepted Answer

ZZZ_tmp
17
4/10/2015 11:32:35 PM

Popular Answer

It might not be as simple as it seems, depending on the database utilized. If MsSql is being used, no configuration is required, and the acceptable response is perfect. but utilizingLocalDB may require some setting up.

For instanceMySql must register as a provider

[DbConfigurationType(typeof(CodeConfig))] // point to the class that inherit from DbConfiguration
public class ApplicationDbContext : DbContext
{
    [...]
}

public class CodeConfig : DbConfiguration
{
    public CodeConfig()
    {
        SetDefaultConnectionFactory(new MySql.Data.Entity.MySqlConnectionFactory());
        SetProviderServices("MySql.Data.MySqlClient",
                    new MySql.Data.MySqlClient.MySqlProviderServices());
    }
}

PostgreSql provider must be registered in both the system.data and entityFramework sections. You can utilize this by usingSystem.Data.Entity.DbConfiguration.Loaded event. same applies toOracle .

Check out this blog post for a detailed explanation: http://bleedingnedge.com/2015/11/01/entity-framework-6-with-asp-net-5/



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow