// 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; using System.Text.RegularExpressions; 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); Table t1 = db.GetTable(); Console.WriteLine("Contains:"); IEnumerable a = t1.Where(r => r.f2.Contains("B")); foreach(T1 r in a) { Console.WriteLine(r.f1 + " " + r.f2); } Console.WriteLine("Regex:"); IEnumerable b = t1.ToList().Where(r => Regex.IsMatch(r.f2, "^.*B.*$")); foreach(T1 r in b) { Console.WriteLine(r.f1 + " " + r.f2); } } } } }