• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
LINQ Internals - STLDODN
 

LINQ Internals - STLDODN

on

  • 2,932 views

Though Language INtegrated Query provides a revolutionary way to write code in C# 3.0 and Visual Basic 9, it is powerless without several enabling language features and libraries. This session will ...

Though Language INtegrated Query provides a revolutionary way to write code in C# 3.0 and Visual Basic 9, it is powerless without several enabling language features and libraries. This session will explore the technologies that make LINQ possible and show how you can use the same techniques to make LINQ work for you.

Presented Aug. 28 & 29, 2009 at St. Louis Day of .NET

Statistics

Views

Total Views
2,932
Views on SlideShare
2,925
Embed Views
7

Actions

Likes
0
Downloads
46
Comments
0

2 Embeds 7

http://www.slideshare.net 5
https://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    LINQ Internals - STLDODN LINQ Internals - STLDODN Presentation Transcript

    •      
    •       
    •   o o  o o
    •  o   o
    • var entry = new { Dim entry = New With { _ Title = "Dear Diary", .Title = "Dear Diary", _ DateTime.Now DateTime.Now _ }; } Console.WriteLine("{0:d}: {1}", Console.WriteLine("{0:d}: {1}", _ entry.Now, entry.Title); entry.Now, entry.Title) var Dim
    •  static Module  using Imports  Imports System.Runtime.CompilerServices Module StringExtensions <Extension()> _ Public Sub Print(ByVal aString As String) Console.WriteLine(aString) End Sub End Module Dim hello = "Hello from StringExtensions" hello.Print()
    •  this static void ForEach<T>(this IEnumerable<T> source, Action<T> action) { foreach (T o in source) action(o); }  delegate void Action(); delegate void Action<T>(T arg); delegate void Action<T1, T2>(T1 arg1, T2 arg2); delegate TResult Func<TResult>(); delegate TResult Func<T, TResult>(T arg); delegate TResult Func<T1, T2, TResult>(T1 arg1, T2 arg2);
    •  delegate string MyDelegate(int i); static string MyMethod(int i) { … } MyDelegate del1 = new MyDelegate(MyMethod); // C# 1.0 MyDelegate del2 = delegate(int i) { … }; // C# 2.0 MyDelegate del3 = MyMethod; // C# 2.0 MyDelegate del4 = (int i) => { … }; // C# 3.0 Func<int, string> del5 = i => { … }; // C# 3.0  Dim del4 As MyDelegate = Function(i As Integer) …
    •    Expression<Func<int, int>> inc = (a => a + 1);  ParameterExpression CS$a; Expression<Func<int, int>> inc = Expression.Lambda<Func<int, int>>( Expression.Add( CS$a = Expression.Parameter(typeof(int), "a"), Expression.Constant(1, typeof(int))), new ParameterExpression[] { CS$a });
    •  var names = from s in Students where s.Age % 2 == 0 orderby s.Name descending select s.Name;  IEnumerable<string> names = Students.Where(s => s.Age % 2 == 0) .OrderByDescending(s => s.Name) .Select(s => s.Name);
    •  o o  o  o
    •  o   o  o   o   o o  o   o   o  o 
    •              
    •  from x1 in e1 join x2 in e2 on k1 equals k2 …  from * in ( e1 ) . Join( e2 , x1 => k1 , x2 => k2 , (x1 , x2) => new { x1 , x2 }) …  o this o o o o
    •  o EqualityComparer<TKey>.Default  o Equals() GetHashcode() o  IEqualityComparer<TKey> o o
    •  into o o Func<TOuter, TInner, TResult> resultSelector  into o o o Func<TOuter, IEnumerable<TInner>, TResult> resultSelector  o DefaultIfEmpty() from x1 in e1 join x2 in e2 on k1 equals k2 into j from xj in j . DefaultIfEmpty() …
    •  from o IEnumerable<T>  from x1 in e1 from x2 in e2 …  from * in ( e1 ) . SelectMany( x1 => e2 , ( x1 , x2 ) => new { x1 , x2 } ) …  * o
    •   o IEnumerable<T>  o yield return  o o o o
    •  o o  o • foreach o  o  o
    •  o o IEnumerable<>  o o EnumerableRowCollection<DataRow> AsEnumerable(this DataTable source) o EnumerableRowCollectionExtensions  o Cast<T>() OfType<T>() o foreach from MyType obj in MyArrayList …
    •   o IQueryable<T> public interface IQueryable : IEnumerable { Type ElementType { get; } Expression Expression { get; } IQueryProvider Provider { get; } } public interface IQueryable<T> : IEnumerable<T>, IQueryable, IEnumerable { }
    •  public interface IQueryProvider { IQueryable CreateQuery(Expression expression); IQueryable<TElement> CreateQuery<TElement>(Expression expression); object Execute(Expression expression); TResult Execute<TResult>(Expression expression); }
    • public static TSource First<TSource>( this IQueryable<TSource> source) { return source.Provider.Execute<TSource>( Expression.Call(null, ((MethodInfo) MethodBase.GetCurrentMethod()) .MakeGenericMethod(new Type[] { typeof(TSource) }), new Expression[] { source.Expression } ) ); }
    •  IEnumerable IQueryable   o o  o o
    •   o  o o o