【问题标题】:Mvc 4 Code First with Mysql使用 Mysql 的 Mvc 4 代码优先
【发布时间】:2015-06-20 09:51:45
【问题描述】:

我想在 asp.net mvc 4 中使用 mysql。 添加了参考。

  • Mysql.Data.dll
  • Mysql.Data.Entity.dll
  • Mysql.Web.dll

在连接字符串中添加了 web.config 文件。

<add name="DBEntities" connectionString="Server=localhost; port=3306; Database=dbprojectname; Uid=root; Pwd=;" providerName="MySql.Data.MySqlClient" />

添加模型

  public class User
{
    [Key]
    public int user_id { get; set; }
    public string username { get; set; }
    public string password { get; set; }
    public string url { get; set; }
    public string name { get; set; }
    public string surname { get; set; }
    public string email { get; set; }
    public string avatar { get; set; }
    public string rank { get; set; }
    public string status { get; set; }
    public DateTime date { get; set; }
}
 public class DbEntities : DbContext
 {
     public DbSet<User> User { get; set; }
 }

并创建控制器,但我有一个错误

无法检索“WSDashboard.Models.User”的元数据。使用 相同的 DbCompiledModel 来创建针对不同类型的上下文 不支持数据库服务器。相反,创建一个单独的 正在使用的每种服务器类型的 DbCompiledModel。

【问题讨论】:

标签: c# mysql asp.net asp.net-mvc


【解决方案1】:

伙计,这是重复的,但 Yurko 的答案在这里:https://stackoverflow.com/a/25640707/3902210

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多