// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity; using System.Linq; [Table("t1")] public class T1 { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] [Column("f1")] public int F1 { get; set; } [Column("f2")] public string F2 { get; set; } } public class MySqlDbContext : DbContext { public MySqlDbContext() : base("MySQL") { } public DbSet T1 { get; set; } } public class Program { public static void Main(String[] args) { Console.WriteLine("MySQL from C# (EF)"); using(MySqlDbContext db = new MySqlDbContext()) { List res = db.T1.ToList(); foreach(T1 o in res) { Console.WriteLine(o.F1 + " " + o.F2); } } } }