Exemplo n.º 1
0
        private static void DistributedJoinQueryExample(
            ICacheClient <int, Employee> employeeCache,
            ICacheClient <int, Organization> organizationCache)
        {
            const string orgName = "Apache";

            var queryOptions = new QueryOptions
            {
                EnableDistributedJoins = true,
                Timeout = new TimeSpan(0, 1, 0)
            };

            IQueryable <ICacheEntry <int, Employee> >     employees     = employeeCache.AsCacheQueryable(queryOptions);
            IQueryable <ICacheEntry <int, Organization> > organizations = organizationCache.AsCacheQueryable(queryOptions);

            IQueryable <ICacheEntry <int, Employee> > qry =
                from employee in employees
                from organization in organizations
                where employee.Value.OrganizationId == organization.Key && organization.Value.Name == orgName
                select employee;


            Console.WriteLine();
            Console.WriteLine($">>> Employees working for {orgName} using distributed joins:");

            foreach (ICacheEntry <int, Employee> entry in qry)
            {
                Console.WriteLine(">>>     " + entry.Value);
            }

            Console.WriteLine($">>> Generated SQL: {qry.ToCacheQueryable().GetFieldsQuery().Sql}");
        }
Exemplo n.º 2
0
        private static void JoinQueryExample(
            ICacheClient <AffinityKey, Employee> employeeCache,
            ICacheClient <int, Organization> organizationCache)
        {
            const string orgName = "Apache";

            IQueryable <ICacheEntry <AffinityKey, Employee> > employees     = employeeCache.AsCacheQueryable();
            IQueryable <ICacheEntry <int, Organization> >     organizations = organizationCache.AsCacheQueryable();

            IQueryable <ICacheEntry <AffinityKey, Employee> > qry =
                from employee in employees
                from organization in organizations
                where employee.Value.OrganizationId == organization.Key && organization.Value.Name == orgName
                select employee;


            Console.WriteLine();
            Console.WriteLine($">>> Employees working for {orgName}:");

            foreach (ICacheEntry <AffinityKey, Employee> entry in qry)
            {
                Console.WriteLine(">>>     " + entry.Value);
            }

            Console.WriteLine($">>> Generated SQL: {qry.ToCacheQueryable().GetFieldsQuery().Sql}");
        }
Exemplo n.º 3
0
        private static void FieldsQueryExample(ICacheClient <int, Employee> cache)
        {
            var qry = cache.AsCacheQueryable().Select(entry => new { entry.Value.Name, entry.Value.Salary });

            Console.WriteLine();
            Console.WriteLine(">>> Employee names and their salaries:");

            foreach (var row in qry)
            {
                Console.WriteLine($">>>     [Name={row.Name}, salary={row.Salary}{']'}");
            }

            Console.WriteLine($">>> Generated SQL: {qry.ToCacheQueryable().GetFieldsQuery().Sql}");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Queries names and salaries for all employees.
        /// </summary>
        /// <param name="cache">Cache.</param>
        private static void LinqFieldsExample(ICacheClient <int, Employee> cache)
        {
            var qry = cache.AsCacheQueryable().Select(entry => new { entry.Value.Name, entry.Value.Salary });

            Console.WriteLine();
            Console.WriteLine(">>> Employee names and their salaries (LINQ):");

            foreach (var row in qry)
            {
                Console.WriteLine(">>>     [Name=" + row.Name + ", salary=" + row.Salary + ']');
            }

            Console.WriteLine();
            Console.WriteLine(">>> Generated SQL:");
            Console.WriteLine(">>> " + qry.ToCacheQueryable().GetFieldsQuery().Sql);
        }
Exemplo n.º 5
0
        private static void QueryExample(ICacheClient <int, Employee> cache)
        {
            const int zip = 94109;

            IQueryable <ICacheEntry <int, Employee> > qry =
                cache.AsCacheQueryable().Where(emp => emp.Value.Address.Zip == zip);

            Console.WriteLine();
            Console.WriteLine($">>> Employees with zipcode {zip}:");

            foreach (ICacheEntry <int, Employee> entry in qry)
            {
                Console.WriteLine(">>>    " + entry.Value);
            }

            Console.WriteLine($">>> Generated SQL: {qry.ToCacheQueryable().GetFieldsQuery().Sql}");
        }
Exemplo n.º 6
0
        private static void CompiledQueryExample(ICacheClient <int, Employee> cache)
        {
            const int zip = 94109;

            var cache0 = cache.AsCacheQueryable();

            // Compile cache query to eliminate LINQ overhead on multiple runs.
            Func <int, IQueryCursor <ICacheEntry <int, Employee> > > qry =
                CompiledQuery.Compile((int z) => cache0.Where(emp => emp.Value.Address.Zip == z));

            Console.WriteLine();
            Console.WriteLine(">>> Employees with zipcode {0} using compiled query:", zip);

            foreach (ICacheEntry <int, Employee> entry in qry(zip))
            {
                Console.WriteLine(">>>    " + entry.Value);
            }
        }