public void Run() { ForEachMethod(); ConsoleUtility.BlankLine(); DelegateMethod(); ConsoleUtility.BlankLine(); }
public void Run() { ConsoleUtility.PrintInfo(".net 3.5 querying objects using a linq method extension."); List <Product> products = Product.GetSampleProducts(); var text = products.Where(p => p.Price > 10).ToStringTable(new[] { "Name", "Price" }, item => item.Name, item => string.Format("£ {0:0.00}", item.Price)); ConsoleUtility.PrintSuccess(text); ConsoleUtility.BlankLine(); }
public void Run() { ConsoleUtility.PrintInfo(".Net 2 querying objects using a predicate delegate {T}."); List <Product> products = Product.GetSampleProducts(); Predicate <Product> test = new Predicate <Product>(MatchProduct); List <Product> matches = products.FindAll(test); var text = matches.ToStringTable(new[] { "Name", "Price" }, item => item.Name, item => string.Format("£ {0:0.00}", item.Price)); ConsoleUtility.PrintSuccess(text); ConsoleUtility.BlankLine(); }
public void Run() { ConsoleUtility.PrintInfo(".net 3.5 querying objects using linq to xml with a query expression."); string text = string.Empty; using (var db = new LinqDemoDataContext()) { if (db.Products.Count() == 0) { ConsoleUtility.PrintInfo("Populating products to database..."); var entities = Model.Product.GetSampleProducts().Select(item => new Edward.Wilde.CSharp.Features.Querying.net_3.Product() { Id = item.Id, Name = item.Name, SupplierId = item.SupplierId, Price = item.Price }); db.Products.InsertAllOnSubmit(entities); } if (db.Suppliers.Count() == 0) { ConsoleUtility.PrintInfo("Populating suppliers to database..."); var entities = Model.Supplier.GetSampleSuppliers().Select(item => new Edward.Wilde.CSharp.Features.Querying.net_3.Supplier() { Id = item.Id, Name = item.Name }); db.Suppliers.InsertAllOnSubmit(entities); } var items = from p in db.Products join s in db.Suppliers on p.SupplierId equals s.Id where p.Price > 10 orderby s.Name select new { Name = p.Name, Price = p.Price, SupplierName = s.Name }; text = items.ToStringTable(new[] { "Name", "Price", "Supplier" }, item => item.Name, item => item.Price, item => item.SupplierName); db.SubmitChanges(); ConsoleUtility.PrintSuccess(text); } ConsoleUtility.BlankLine(); }
public void Run() { ConsoleUtility.PrintInfo(".net 3.5 querying objects using linq query expression."); var products = Model.Product.GetSampleProducts(); var suppliers = Model.Supplier.GetSampleSuppliers(); var items = from p in products join s in suppliers on p.SupplierId equals s.Id where p.Price > 10 orderby s.Name, p.Name select new { Name = p.Name, Supplier = s.Name, Price = p.Price }; var text = items.ToStringTable(new[] { "Name", "Supplier", "Price" }, item => item.Name, item => item.Supplier, item => string.Format("£ {0:0.00}", item.Price)); ConsoleUtility.PrintSuccess(text); ConsoleUtility.BlankLine(); }
public void Run() { ConsoleUtility.PrintInfo(".net 3.5 querying objects using linq to xml with a query expression."); var doc = XDocument.Parse(Xml); var items = from p in doc.Descendants("Product") join s in doc.Descendants("Supplier") on(int) p.Attribute("SupplierID") equals(int) s.Attribute("SupplierID") where (decimal)p.Attribute("Price") > 10 orderby(string) s.Attribute("Name"), (string)p.Attribute("Name") select new { SupplierName = (string)s.Attribute("Name"), ProductName = (string)p.Attribute("Name") }; var text = items.ToStringTable(new[] { "Name", "Supplier" }, item => item.ProductName, item => item.SupplierName); ConsoleUtility.PrintSuccess(text); ConsoleUtility.BlankLine(); }