【发布时间】:2017-02-24 21:00:46
【问题描述】:
我正在使用 linux 上的 dotnet 核心,我正在尝试使用连接字符串配置我的 DbContext 到 mysql 服务器。
我的 DbContext 看起来像这样:
using Microsoft.EntityFrameworkCore;
using Models.Entities;
namespace Models {
public class SomeContext : DbContext
{
//alot of dbSets...
public DbSet<SomeEntity> SomeDbSet { get; set; }
public SomeContext(DbContextOptions<SomeContext> options) : base(options) {
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMysql //Cannot find this method
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//using modelBuilder to map some relationships
}
}
}
我的依赖项如下所示:
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
"Microsoft.AspNetCore.Mvc":"1.0.0",
"Microsoft.EntityFrameworkCore": "1.0.1",
"MySql.Data.Core": "7.0.4-ir-191",
"MySql.Data.EntityFrameworkCore": "7.0.4-ir-191"
},
我还尝试在下面的代码中使用我的 Startup.cs 中的 mysql 服务器
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var connection = @"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.AspNetCore.NewDb;Trusted_Connection=True;";
services.AddDbContext<SomeContext>(options => options.UseMysql); //Cannot find UseMysql*
}
我试图改变我的指令
using Microsoft.EntityFrameworkCore;
到
using MySQL.Data.EntityFrameworkCore;
这有道理吗?可能是?但是所有对 DbContext 和 DbSet 的引用都消失了,所以我想解决方案是混合的??
【问题讨论】:
标签: c# mysql entity-framework asp.net-core