【发布时间】:2026-02-12 17:30:01
【问题描述】:
我使用 MySQL EF 6(MySQL.Data.Entity 包)连接到 MySQL DB。如果我使用构造函数 connectionStringName :base("MyContext"),一切都很好。但它不起作用,如果我直接使用 connectionString :base("server=localhost;port=3306;database=wordpress;uid=root")。应用程序引发错误System.ArgumentException: Keyword not supported: 'port'.
我的项目需要直接使用连接字符串。有谁知道如何修理它?谢谢
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class MyContext : DbContext
{
static MyContext()
{
Database.SetInitializer<MyContext>(null);
}
public MyContext()
//:base("server=localhost;port=3306;database=wordpress;uid=root;password=") not work
:base("MyContext") // it worked if using connectionStringName
{
}
}
【问题讨论】:
标签: c# mysql entity-framework