EntityFramework 6.0< Code First > 连接 Mysql数据库
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6"> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/> <providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" /> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework>
<connectionStrings> <add name="MyContext" connectionString="Data Source=localhost;port=3306;Initial Catalog=数据库名称;user id=Mysql的登录用户名;password=Mysql server密码;" providerName="MySql.Data.MySqlClient"/> </connectionStrings>
using System.Data.Entity; namespace StudyEF { public class MyContext : DbContext { public MyContext() : base("name=MyContext") { } public DbSet<Data> Datas { get; set; } } public class Data { public int Id { get; set; } public string Name { get; set; } } class Program { static void Main(string[] args) { Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>()); var context = new MyContext(); context.Datas.Add(new Data{Name="EF6-MySql"}); context.SaveChanges(); } } }
EntityFramework 6.0< Code First > 连接 Mysql数据库,古老的榕树,5-wow.com
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。