[C#.NET][Entity Framework] Connect Maria Database
Maria 來自於 MySQL 之父,據說比 MySQL 團隊還要強,
http://www.openfoundry.org/index.php?option=com_content&task=view&id=8974&Itemid=4;isletter=1
http://www.ithome.com.tw/node/82854
第一次嘗試使用它,晃了一下官網,沒有看到支援.NET的資訊
https://downloads.mariadb.org/
所以使用 MySQL Connector/Net 來連接它
http://dev.mysql.com/downloads/connector/net/
使用版本
MySql.Data,MySql.Data.Entity.EF6 ver.6.8.3.0
有了 Connector,在 ADO.NET ,連線字串以及 SQL 語法,都可直接套 MySQL 的寫法
conn.Open();
MySqlCommand comm = conn.CreateCommand();
comm.CommandText = "INSERT INTO Members(id,name,age) VALUES(@id,@name,@age)";
comm.Parameters.AddWithValue("@id", 0);
comm.Parameters.AddWithValue("@name", "小章");
comm.Parameters.AddWithValue("@age", 18);
comm.ExecuteNonQuery();
conn.Close();
Code First 也沒有問題,請參考上篇
http://www.dotblogs.com.tw/yc421206/archive/2014/03/15/144399.aspx
db.Members.Add(new Member() { Age = 12, Name = "小章" });
db.Members.Add(new Member() { Age = 11, Name = "yao" });
db.SaveChanges();
文章出自:http://www.dotblogs.com.tw/yc421206/archive/2014/03/17/144417.aspx
若有謬誤,煩請告知,新手發帖請多包涵
Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET