转载地址:http://www.cnblogs.com/wintersun/archive/2010/12/12/1903861.html
Entity Framework 4.0 也可以支持大名鼎鼎的MySql,这篇POST将向展示如何实现EF+MySql数据库的结构.首先,你必须下载 MySQL Connector/NET 6.3.5 ,也就是.net下连接MySql数据库的驱动程序. 还是像以往一样的,增加一个Entity data model:
将下面选择DataSource, 选择MySQL database 做为数据源.
接下来几步和以前一样,选择要Mapping的Tables:
好了,让我们来测试一下:
1: using(var context = new MySqlEntities())
2: { var myEvents = from e in context.Events
3: from a in e.Attendees
4: where a.Person.FirstName == "Gunnar" &&
5: a.Person.LastName == "Peipman"
6: select e; Console.WriteLine("My events: ");
7: foreach(var e in myEvents)
8: {
9: Console.WriteLine(e.Title);
10: }
11: }