// 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.Linq; using System.Data.Linq; using System.Data.Linq.SqlClient; using System.Data.Linq.Mapping; using System.Data.SqlClient; public class LINQCount { [Table(Name="T1")] public class T1 { [Column(IsPrimaryKey=true)] public int F1; [Column] public string F2; } public static void Main(string[] args) { SqlConnection con = new SqlConnection(@"Server=ARNEPC4;Integrated Security=SSPI;Database=Test"); DataContext db = new DataContext(con); db.Log = Console.Out; Table t1 = db.GetTable(); int n1 = t1.Where(r => r.F1==2).Count(); Console.WriteLine(n1); int n2 = t1.Count(r => r.F1==2); Console.WriteLine(n1); con.Close(); } }