// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Linq; using System.Data.SqlClient; using System.Data.Linq; using System.Data.Linq.Mapping; using System.Data.Linq.SqlClient; namespace E { [Table(Name="T1")] public class T1 { [Column(Name="F1",IsPrimaryKey=true)] public int f1; [Column(Name="F2")] public string f2; } public class Program { public static void Main(string[] args) { using(SqlConnection con = new SqlConnection(@"Server=ARNEPC3\SQLEXPRESS2008;Integrated Security=SSPI;Database=Test")) { DataContext db = new DataContext(con); db.Log = Console.Out; Table t1 = db.GetTable(); IEnumerable q1 = t1; foreach(T1 r in q1) { Console.WriteLine(r.f1 + " " + r.f2); } IEnumerable q2 = t1.Where(r => r.f1 > 1); foreach(T1 r in q2) { Console.WriteLine(r.f1 + " " + r.f2); } T1 q3 = t1.First(r => r.f1 > 1); Console.WriteLine(q3.f1 + " " + q3.f2); } } } }