标签:flush sp1 l数据库 led 卸载 alter int you class
(学习大佬tkbSimplest的CodeFirst开发系列)
MySQL for Visual Studio 1.2.8版本安装失败回滚,只安装1.0.2版本
public class Donator
{
public int DonatorId { get; set; }
public string Name { get; set; }
public decimal Amount { get; set; }
public DateTime DonateDate { get; set; }
}
[DbConfigurationType(typeof(MySql.Data.EntityFramework.MySqlEFConfiguration))]
public class Context : DbContext
{
public Context()
: base("name=CodeFirst")
///调用了父类的构造函数,并且传入了一个键值对,键是name,值是CodeFirst,这个键值对是定义在应用程序的配置文件中的
{
}
public DbSet<Donator> Donators { get; set; }
}
class Program
{
static void Main(string[] args)
{
using (var context = new Context())
{
context.Database.CreateIfNotExists();//如果数据库不存在时则创建
context.Donators.Add(
new Donator
{
DonatorId = 1,
Name = "Niu",
Amount = 50,
DonateDate = DateTime.Now
});
context.SaveChanges();
}
Console.Write("DB has Created!");//提示DB创建成功
Console.Read();
}
<connectionStrings>
<add name="CodeFirst" connectionString="Data Source=localhost;port=3306;Initial Catalog=CodeFirst;user id=root;password=root;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
运行:
‘MySql.Data.Entity.EFMySqlCommand.set_DbConnection(System.Data.Common.DbConnection)‘ to access method ‘MySql.Data.MySqlClient.MySqlConnection.get_Settings()‘ failed."
呃。。。百度半天各种修改,卒。Google一下
Oracle renamed the package to MySql.Data.EntityFramework for v8.x. You need to uninstall MySql.Data.Entity and install MySql.Data.EntityFramework.
1. use mysql;
2. alter user ‘root‘@‘localhost‘ identified with mysql_native_password by ‘自个的密码‘;
3. flush privileges;
EntityFramework+MySql数据库(code first方式)
标签:flush sp1 l数据库 led 卸载 alter int you class
原文地址:https://www.cnblogs.com/SurroundSea/p/9897085.html