2017-06-20 100 views
0

有没有什么办法可以在.net core中使用DbConfiguration? 对于前:如何在ASP.NET Core中使用DbConfiguration类

public class DbConfig : DbConfiguration 
{ 
    public DbConfig() 
    { 
     SetProviderServices("System.Data.SqlClient", 
     System.Data.Entity.SqlServer.SqlProviderServices.Instance); 
    } 
} 

我认为我需要得到一个.NET Framework DLL,为了使用该类引用它在我的项目?我这样做的目的是把一个注释上的DbContext类象下面这样:

[DbConfigurationType(typeof(DbConfig))] 
    public class MyDbContext : DbContext 
在.NET的核心方式

,并最终实现this

回答

2

如果您正在开发使用完整的.NET框架(.NET 4.6)你的ASP.NET的核心,那么所有你需要做的就是添加的依赖如下您project.json文件

"frameworks": { 
    "net46": {} 
} 

的DbConfiguration来自EntityFramework的类将提供给你。

但是,如果您使用.NET Core开发ASP.NET Core,则需要使用EntityFramework Core Configuring DbContext

相关问题