/// <summary> /// Executing this method will perform the operations of the sample using NCache LINQ /// </summary> public static void Run() { Console.WindowWidth = 100; string select; // Load data in cache if (!LoadCache()) { Console.ReadLine(); return; } Console.WriteLine("Cache Loaded !"); IQueryable <Product> products = new NCacheQuery <Product>(_cache); var result1 = from product in products where product.Id > 10 select product; if (result1 != null) { PrintHeader(); foreach (Product p in result1) { Console.WriteLine("ProductID : " + p.Id); } } else { Console.WriteLine("No record found."); } var result2 = from product in products where product.Category == "4" select product; if (result2 != null) { PrintHeader(); foreach (Product p in result2) { Console.WriteLine("ProductID : " + p.Id); } } else { Console.WriteLine("No record found."); } var result3 = from product in products where product.Id < 10 && product.UnitPrice == 1 select product; if (result3 != null) { PrintHeader(); foreach (Product p in result3) { Console.WriteLine("ProductID : " + p.Id); } } else { Console.WriteLine("No record found."); } // Dispose cache once done. _cache.Dispose(); }
static void Main(string[] args) { Console.WindowWidth = 100; string select; if (!LoadCache()) { Console.ReadLine(); return; } Console.WriteLine("Cache Loaded !"); IQueryable<Product> products = new NCacheQuery<Product>(_cache); do { Console.WriteLine("\n\n1> from product in products where product.ProductID > 10 select product;"); Console.WriteLine("2> from product in products where product.Category == 4 select product;"); Console.WriteLine("3> from product in products where product.ProductID < 10 && product.Supplier == 1 select product;"); Console.WriteLine("x> Exit"); Console.Write("?> "); select = Console.ReadLine(); switch (select) { case "1": try { var result1 = from product in products where product.ProductID > 10 select product; if (result1 != null) { PrintHeader(); foreach (Product p in result1) { Console.WriteLine("ProductID : " + p.ProductID); } } else { Console.WriteLine("No record found."); } } catch (Exception) { Console.WriteLine(_error); } Console.WriteLine("Press Enter to continue.."); Console.ReadLine(); break; case "2": try { var result2 = from product in products where product.Category == 4 select product; if (result2 != null) { PrintHeader(); foreach (Product p in result2) { Console.WriteLine("ProductID : " + p.ProductID); } } else { Console.WriteLine("No record found."); } } catch (Exception) { Console.WriteLine(_error); } Console.WriteLine("Press Enter to continue.."); Console.ReadLine(); break; case "3": try { var result3 = from product in products where product.ProductID < 10 && product.Supplier == 1 select product; if (result3 != null) { PrintHeader(); foreach (Product p in result3) { Console.WriteLine("ProductID : " + p.ProductID); } } else { Console.WriteLine("No record found."); } } catch (Exception) { Console.WriteLine(_error); } Console.WriteLine("Press Enter to continue.."); Console.ReadLine(); break; case "x": break; } } while (select != "x"); _cache.Dispose(); Environment.Exit(0); }
static void Main(string[] args) { Console.WindowWidth = 100; string select; if (!LoadCache()) { Console.ReadLine(); return; } Console.WriteLine("Cache Loaded !"); IQueryable <Product> products = new NCacheQuery <Product>(_cache); do { Console.WriteLine("\n\n1> from product in products where product.ProductID > 10 select product;"); Console.WriteLine("2> from product in products where product.Category == 4 select product;"); Console.WriteLine("3> from product in products where product.ProductID < 10 && product.Supplier == 1 select product;"); Console.WriteLine("x> Exit"); Console.Write("?> "); select = Console.ReadLine(); switch (select) { case "1": try { var result1 = from product in products where product.ProductID > 10 select product; if (result1 != null) { PrintHeader(); foreach (Product p in result1) { Console.WriteLine("ProductID : " + p.ProductID); } } else { Console.WriteLine("No record found."); } } catch (Exception) { Console.WriteLine(_error); } Console.WriteLine("Press Enter to continue.."); Console.ReadLine(); break; case "2": try { var result2 = from product in products where product.Category == 4 select product; if (result2 != null) { PrintHeader(); foreach (Product p in result2) { Console.WriteLine("ProductID : " + p.ProductID); } } else { Console.WriteLine("No record found."); } } catch (Exception) { Console.WriteLine(_error); } Console.WriteLine("Press Enter to continue.."); Console.ReadLine(); break; case "3": try { var result3 = from product in products where product.ProductID < 10 && product.Supplier == 1 select product; if (result3 != null) { PrintHeader(); foreach (Product p in result3) { Console.WriteLine("ProductID : " + p.ProductID); } } else { Console.WriteLine("No record found."); } } catch (Exception) { Console.WriteLine(_error); } Console.WriteLine("Press Enter to continue.."); Console.ReadLine(); break; case "x": break; } } while (select != "x"); _cache.Dispose(); Environment.Exit(0); }