// 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.Objects; using TestEF; namespace EFAggr { public class Program { public static void Normal(TestEFContext ctx) { // get one t1 o = ctx.t1.First(r => r.f1 == 2); Console.WriteLine(o.f1 + " " + o.f2); // get all IList all = ctx.t1.ToList(); foreach(t1 one in all) { Console.WriteLine(one.f1 + " " + one.f2); } // get some IList some = ctx.t1.Where(r => r.f1 == 2).ToList(); foreach(t1 one in some) { Console.WriteLine(one.f1 + " " + one.f2); } // get count int aggr = ctx.t1.Count(); Console.WriteLine(aggr); } public static void Trace(TestEFContext ctx) { // get one IEnumerable tmpo = ctx.t1.Where(r => r.f1 == 2); Console.WriteLine(((ObjectQuery)tmpo).ToTraceString()); IList o = tmpo.ToList(); Console.WriteLine(o[0].f1 + " " + o[0].f2); // get all IEnumerable tmpall = ctx.t1; Console.WriteLine(((ObjectQuery)tmpall).ToTraceString()); IList all = tmpall.ToList(); foreach(t1 one in all) { Console.WriteLine(one.f1 + " " + one.f2); } // get some IEnumerable tmpsome = ctx.t1.Where(r => r.f1 == 2); Console.WriteLine(((ObjectQuery)tmpsome).ToTraceString()); IList some = tmpsome.ToList(); foreach(t1 one in some) { Console.WriteLine(one.f1 + " " + one.f2); } // get count IEnumerable tmpaggr = ctx.t1.GroupBy(r => 0).Select(g => g.Count()); Console.WriteLine(((ObjectQuery)tmpaggr).ToTraceString()); IList aggr = tmpaggr.ToList(); Console.WriteLine(aggr[0]); } public static void Main(string[] args) { TestEFContext ctx = new TestEFContext(); Normal(ctx); Trace(ctx); ctx.Dispose(); } } }