标签:blog http io ar sp 数据 div on 2014
闲下来,充下电,在网上找了一番,做个笔记。
mysql 绿色版。懒得费事,放百度云盘了http://pan.baidu.com/s/1pJJSJwf
然后是搞ef6和mysql的依赖库
就这些,然后是一段别人写的代码。
using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using MySql.Data.Entity; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace mysqlTest { [DbConfigurationType(typeof(MySqlEFConfiguration))] public class MyContext:DbContext { public MyContext() : base("name=dbconnetion") { Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MyContext>()); } public DbSet<User> Users { get; set; } } public class User { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [MaxLength(30)] public string UserName { get; set; } [MaxLength(30)] public string PassWord { get; set; } } public class MainClass { public static void Main (string[] args) { Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>()); var context = new MyContext(); context.Users.Add(new User { UserName = "EF6-MySQL-Code-First" }); var i= context.SaveChanges(); Console.Write (i); Console.ReadKey (); } } }
刚开始运行报了个错,看了下,然后把数据库删了,再搞就好了,ef要自己写些东西到库里面吧,没深究;
然后成功了,看了下库里面有两张表。
好了,睡觉,自己mark一下。
标签:blog http io ar sp 数据 div on 2014
原文地址:http://www.cnblogs.com/jmzs/p/4104538.html