This project has moved. For the latest updates, please go here.

Query Demo

This demo creates a query that joins a list of types with their type members and groups them by assembly name and member type.

using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;

using NQuery;

namespace NQueryQuickDemo1
    class Program
        static void Main(string[] args)
            // Get a lists with all types and all members

            Console.WriteLine("Loading types...");
            List<Type> typeList = new List<Type>();
            List<MemberInfo> memberList = new List<MemberInfo>();
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                Type[] types = assembly.GetTypes();

                foreach (Type t in types)

            // Create data context containing the tables "Types" and "Members"

            DataContext dataContext = new DataContext();
            dataContext.Tables.Add(typeList.ToArray(), "Types");
            dataContext.Tables.Add(memberList.ToArray(), "Members");

            Query query = new Query(dataContext);
            query.Text = @"
                SELECT  t.Assembly.ManifestModule.Name AS AssemblyName,
                        m.MemberType.ToString() AS MemberType,
                        COUNT(*) AS MemberCount
                FROM    Types t
                            INNER JOIN Members m ON m.DeclaringType.AssemblyQualifiedName = t.AssemblyQualifiedName
                GROUP   BY t.Assembly.ManifestModule.Name, m.MemberType

            // Execute the query and get a DataTable containing the result

            Console.WriteLine("Executing query...");
            DataTable result = query.ExecuteDataTable();
            result.TableName = "Types";

Last edited Aug 26, 2006 at 3:27 PM by terrajobst, version 1


No comments yet.