Data sources used for the samples

            Person[] people = new Person[] { 
                new Person("Bill", 31), 
                new Person("John", 30), 
                new Person("Cindy", 25), 
                new Person("Sue", 29) 
            };

            // For testing physical links
            people[0].Friends.Add(people[0]);
            people[0].Friends.Add(people[1]);
            people[1].Friends.Add(people[2]);
            people[2].Friends.Add(people[3]);
            people[3].Friends.Add(people[0]);

            // For testing logical links
            Address[] addresses = new Address[] {
                new Address("Bill", "Redmon"),
                new Address("Bill", "Boston"),
                new Address("Cindy", "New York")
            };

Projections

            query = new NLinqQuery(
                @"  from c in people 
                    from d in people
                    where c.Age > d.Age
                    select new NLinq.Play.Person ( c.Firstname, d.Age )");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);


Result
Sue (25)
John (25)
John (29)
Bill (30)
Bill (25)
Bill (29)

Anonymous types

            query = new NLinqQuery(
                @"  from c in people 
                    select new NLinq.Play.Person { c.Firstname, Age = c.Age * 2}");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);


Result

Bill (62)
John (60)
Cindy (50)
Sue (58)

Physical links

            query = new NLinqQuery(
                @"  from c in people
                    from f in c.Friends
                    select new { c.Firstname, Friend = f.Firstname.Substring(0,1) }");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);


Result

{ Firstname = Sue; Friend = B; }
{ Firstname = Cindy; Friend = S; }
{ Firstname = John; Friend = C; }
{ Firstname = Bill; Friend = B; }
{ Firstname = Bill; Friend = J; }

Ordering

                @"  from c in people
                    orderby c.Age descending, c.Firstname
                    select c");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);


Result

Bill (31)
John (30)
Sue (29)
Cindy (25)

Grouping

            query = new NLinqQuery(
                @"  from m in methods
                    where !m.IsStatic
                    orderby m.Name
                    group m by m.Name into g
                    select new { MethodName = g.Key, Overloads = g.Count() }");

            linq = new LinqToMemory(query);
            linq.AddSource("methods", typeof(string).GetMethods());


Result

{ MethodName = Clone; Overloads = 1; }
{ MethodName = CompareTo; Overloads = 2; }
{ MethodName = Contains; Overloads = 1; }
{ MethodName = CopyTo; Overloads = 1; }
{ MethodName = EndsWith; Overloads = 3; }
{ MethodName = Equals; Overloads = 3; }
{ MethodName = get_Chars; Overloads = 1; }
{ MethodName = get_Length; Overloads = 1; }
{ MethodName = GetEnumerator; Overloads = 1; }
{ MethodName = GetHashCode; Overloads = 1; }
{ MethodName = GetType; Overloads = 1; }
{ MethodName = GetTypeCode; Overloads = 1; }
{ MethodName = IndexOf; Overloads = 9; }
{ MethodName = IndexOfAny; Overloads = 3; }
{ MethodName = Insert; Overloads = 1; }
{ MethodName = IsNormalized; Overloads = 2; }
{ MethodName = LastIndexOf; Overloads = 9; }
{ MethodName = LastIndexOfAny; Overloads = 3; }
{ MethodName = Normalize; Overloads = 2; }
{ MethodName = PadLeft; Overloads = 2; }
{ MethodName = PadRight; Overloads = 2; }
{ MethodName = Remove; Overloads = 2; }
{ MethodName = Replace; Overloads = 2; }
{ MethodName = Split; Overloads = 6; }
{ MethodName = StartsWith; Overloads = 3; }
{ MethodName = Substring; Overloads = 2; }
{ MethodName = ToCharArray; Overloads = 2; }
{ MethodName = ToLower; Overloads = 2; }
{ MethodName = ToLowerInvariant; Overloads = 1; }
{ MethodName = ToString; Overloads = 2; }
{ MethodName = ToUpper; Overloads = 2; }
{ MethodName = ToUpperInvariant; Overloads = 1; }
{ MethodName = Trim; Overloads = 2; }
{ MethodName = TrimEnd; Overloads = 1; }
{ MethodName = TrimStart; Overloads = 1; }

Computed properties

            query = new NLinqQuery(
                @"  from c in people
                    let t = c.Age * 3
                    where t % 2 == 0
                    orderby t descending
                    select new { c.Firstname, t }");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);


Result

{ Firstname = John; t = 90; }

Logical links

            query = new NLinqQuery(
                @"  from p in people
                    join a in addresses on p.Firstname equals a.Owner
                    select new { p.Firstname, a.City }");

            linq = new LinqToMemory(query);
            linq.AddSource("people", people);
            linq.AddSource("addresses", addresses);


Result

{ Firstname = Cindy; City = New York; }
{ Firstname = Bill; City = Redmon; }
{ Firstname = Bill; City = Boston; }


Last edited Sep 5, 2007 at 3:28 PM by sebastienros, version 1

Comments

No comments yet.