LINQ, Take Two Realizing the LINQ to Everything Dream Bart J.F. De Smet blogs.bartdesmet.net/bart

Slides:



Advertisements
Similar presentations
The Microsoft Technical Roadshow 2007 Language Enhancements and LINQ Daniel Moth Developer & Platform Group Microsoft Ltd
Advertisements

Language Integrated Query (LINQ) Martin Parry Developer & Platform Group Microsoft Ltd
Reactive Extension to .NET
Slides license: Creative Commons Attribution Non-Commercial Share Alike See
An Introduction to the Reactive Extensions Ivan Towlson Mindscape.
C# and LINQ Yuan Yu Microsoft Research Silicon Valley.
Bing it on, Reactive Extensions Building a quick search app from scratch in WPF with Rx and Bing.com.
Demystifying the .NET Asynchronous Programming Landscape
Tips, Tricks, and Techniques for Building Killer Silverlight Apps Jeff Prosise
Build-Deploy-Test with Visual Studio Lab Management 2010 Pieter Gheysens Visual Studio ALM MVP – Sparkles User Group Lead VISUG (
Rx Framework Reactive Extensions for.Net and JavaScript Andrea Nasoni & Diego Guidi.
HTML5 That’s what you need to know today Ingo Rammer, thinktecture
.NET Framework V3.5+ & RESTful web services Mike Taulty Developer & Platform Group Microsoft Ltd
WCF RIA Services - Querying and Updating Data SILVERLIGHTSHOW.NET WEBINARS SERIES BRIAN NOYES, CHIEF ARCHITECT, IDESIGN INC 2 FEB 2011.
Visual Studio 2008 and ASP.NET 3.5 Mike Ormond Developer & Platform Group Microsoft Ltd
What’s new in ASP.NET 3.5? Mike Ormond Developer & Platform Group Microsoft Ltd
& Silverlight, Windows Phone 7, Windows Azure, jQuery, OData and RIA Services. Shaken, not stirred. Kevin
Switching on the cloud for Silverlight MSDN Live Meeting Gill Cleeren Microsoft Regional Director – Silverlight MVP Ordina Belgium.
Curing Your Event Processing Blues with Reactive Extensions (Rx)
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Creating and Running Your First C# Program Telerik Software Academy Telerik School Academy.
Parallel Programming in.NET 4.0 Tasks and Threading Ingo Rammer, thinktecture
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
LINQ Programming in C# LINQ CSE Prof. Roger Crawfis.
 Introduction  What is LINQ  Syntax  How to Query  Example Program.
Introducing Visual Studio ® LightSwitch™ Andrew Coates Microsoft DEV201 #auteched #dev201.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
LINQ, Take Two Realizing the LINQ to Everything Dream Bart J.F. De Smet Senior Software Development Engineer Microsoft Corporation.
Reactive Extensions Ye olde introduction and walk-through, with plenty o’ code.
Total Workstation Lockdown: Your Action Plan Jeremy Moskowitz, Group Policy MVP Chief Propeller-Head: GPanswers.com Founder: PolicyPak Software (policypak.com)
NuGet in Depth Making Open Source Suck Less at Microsoft Scott Hanselman
Putting it all together: LINQ as an Example. The Problem: SQL in Code Programs often connect to database servers. Database servers only “speak” SQL. Programs.
Project “Astoria” first announced in Mix 2007 Shared early prototypes, got tons of feedback Now we’re talking about the real deal Production quality bits,
Parallel Programming in.NET 4.0 Tasks and Threading Ingo Rammer, thinktecture
Monads Steve Goguen. About Me Web Developer for Allied Building Supply  ASP.NET, SQL Server, LINQ, etc. Website:
Reactive Extensions (Rx) Explained Presenter: Kevin Grossnicklaus August 5 th, 2011.
Please visit m.ausalgo.com on your device and sign inm.ausalgo.com.
Reactive pattern matching for F# Part of “Variations in F#” research project Tomáš Petříček, Charles University in Prague
Migration and Deployment of Office 2010 Steffen Krause Senior Technical Evangelist Microsoft Deutschland GmbH
Windows Azure for IT Pros Kurt CLAEYS (TSP Windows Azure, Microsoft EMEA)
C#: Future Directions in Language Innovation Anders Hejlsberg TLN307 Technical Fellow Microsoft Corporation.
1 ADO.NET Data Services Mike Taulty Developer & Platform Group Microsoft Ltd
Inside LINQ to Objects How LINQ to Objects work Inside LINQ1.
Forthcoming SQL Azure Services: SQL Azure Data Sync & SQL Azure Reporting Mark Scurrell Lead Program Manager Microsoft.
Switch on the LightSwitch Gill Cleeren Microsoft Regional Director / Silverlight MVP Ordina Belgium
.NET Mobile Application Development XML Web Services.
IAP C# 2011 Lecture 2: Delegates, Lambdas, LINQ Geza Kovacs.
Developing SaaS Applications with the Windows Azure Platform Vittorio Bertocci
LINQ Language Integrated Query LINQ1. LINQ: Why and what? Problem Many data sources: Relational databases, XML, in-memory data structures, objects, etc.
Language Integrated Query Mike Taulty Developer & Platform Group Microsoft Ltd
Service Manager 2010 Real Life Example: The coffee workflow Mike Resseler & Alexandre Verkinderen Infront Consulting Group.
Building Robust, Maintainable Coded UI Tests with Visual Studio 2010 Brian Keller Sr. Technical Evangelist – Visual Studio ALM
C# Present and Future Marita Paletsou Software Engineer.
To OData or Not to OData Chris Eargle kodefuguru.com.
What’s new in Azure SDK 1.3 (and 1.4) Peter Himschoot Microsoft Regional Director Belux U2U Trainer/Architect
Building Complete Web Application Using ASP.NET 3.5 & Visual Studio 2008 Omar Khan Group Program Manager Visual Studio.
2 ADO.NET Data Services for the Web Mike Flasko Program Manager, Microsoft “Project Astoria”
Building and Consuming REST-based Data Services for the Web
The Future of C# and Visual Basic
Dive into Application Lifecycle Management with Visual Studio 2010
Automating AD Administration with Windows PowerShell
Rock Hard: C++ Evolving
Glenn Block MEF in the real world Glenn Block
SharePoint & jQuery: Better Together
Unlocking the secrets of REST with WCF
WCF Web API, HTTP your way
Chris Eargle kodefuguru.com
Server & Tools Business
.NET Framework V3.5+ & RESTful web services
Presentation transcript:

LINQ, Take Two Realizing the LINQ to Everything Dream Bart J.F. De Smet blogs.bartdesmet.net/bart

Censored 5 years ago Little recent innovation Where’s the cloud? A Historical Perspective

Why? What? How? Language Integrated Query Monads

IEnumerable IQueryable IEnumerable IQueryable new[] { 42 } SelectMany IEnumerable SelectMany ( this IEnumerable source, Func > selector) Could there be more? Also see for “Project MinLINQ” The Monadic Bind Operator Revealed

from _ in name from s in _.ToUpper() select s from _ in name from s in _.ToUpper() select s name.SelectMany( _ => _.ToUpper(), s => s) name.SelectMany( _ => _.ToUpper(), s => s) Compiler Null-propagating dot string s = name?.ToUpper(); Null-propagating dot string s = name?.ToUpper(); Syntactic sugar One single library function suffices Building the Maybe Monad (For Fun and No Profit)

DEMO Essential LINQ

var src = new Source (); var res = from p in src where p.Price > 100m group p by p.Category; foreach (var p in res) Console.WriteLine(p); Implements IQueryable Implements IQueryable Compiles fine Does it really have to be a runtime check? Query Providers Revisited – Do We Need IQueryable ?

var res = from p in src where p.Price > 100m group p by p.Category; var res = src.Where(p => p.Price > 100m).GroupBy(p => p.Category); Syntactic sugar Can be instance methods Source Filtered Projected Where Select No GroupBy “edge” Leveraging The Query Pattern

var res = from tweet in twitter where tweet. About From Location == “Bart” From From About Location == “LINQ” About where tweet. About Query “learns” class Twitter { public TwitterByFrom Where(Func filter); // Other filter methods } Recipe Method overloads Type state machine Operator overloads Recipe Method overloads Type state machine Operator overloads “Has a” type From operator overloading class TwitterByFrom { public TwitterByAboutFrom Where(Func filter); // Other filter methods // Fields with current filters } select tweet; Custom syntax trees class TweetAboutLoc { public AboutString About; public LocString Location; } class AboutString { FilterAbout operator ==( AboutString f, string s) } class TweetAboutLoc { public AboutString About; public LocString Location; } class AboutString { FilterAbout operator ==( AboutString f, string s) } class TweetAboutFromLoc { public FromString From; public AboutString About; public LocString Location; } class FromString { FilterFrom operator ==( FromString f, string s) } class TweetAboutFromLoc { public FromString From; public AboutString About; public LocString Location; } class FromString { FilterFrom operator ==( FromString f, string s) } Taking It One Step Further

DEMO Query Providers Revisited

Event Processing Systems Rx is a library for composing asynchronous and event-based programs using observable sequences. Queries! LINQ! Way simpler with Rx.NET 3.5 SP1 and 4.0 Silverlight 3, 4, and 5 XNA 4.0 for Xbox 360 Windows Phone 7 JavaScript (RxJS) Download at MSDN Data Developer Center or use NuGet

Environment MoveNext Got next? Application OnNext Have next! IEnumerable IEnumerator IEnumerable IEnumerator IObservable IObserver IObservable IObserver Interactive Reactive Push-Based Data Retrieval

Event Programming Interfaces interface IObservable { IDisposable Subscribe(IObserver observer); } interface IObserver { void OnNext(T value); void OnError(Exception ex); void OnCompleted(); } Both interfaces ship in the.NET 4 BCL

Fixed (MSIL) Translatable (Expression trees) ToQueryable ToObservable ToEnumerable AsQueryable AsEnumerable AsQbservable AsObservable Pull (interactive) Push (reactive) Concurrency (IScheduler) LINQ to *.* What? Where? How? Worker pools Message loops Threads Distributed Duality Homo-iconic IQbservable LINQ to WMI Events ToQbservable IQueryable LINQ to SQL IEnumerable LINQ to Objects IObservable LINQ to Events

IQbservable – The Dual of IQueryable We welcome semantic discussions Extended role for some operators No Execute method interface IQbservable : IObservable { Expression Expression { get; } Type ElementType { get; } IQbservableProvider Provider { get; } } interface IQbservableProvider { IQbservable CreateQuery (Expression expression); }

DEMO LINQ to WMI Events (WQL)

Rx and the Visual Studio Async CTP The essence of the feature Feature based on the “await-pattern” Awaiting Task Returns the single result (of type T) Awaiting IObservable ? We return the last result (of type T) Want all values? Use ToList() first! async Task GetLength(Task name) { string n = await name; return n.Length; } Asynchronously computed value Can await a “future” value Result is async too

Asynchronous Pull-Based Data Access? Await feature is about sequential code Great for single-valued computations What about asynchronous pull-based data collections? public interface IAsyncEnumerable { IAsyncEnumerator GetEnumerator(); } public interface IAsyncEnumerator : IDisposable { T Current { get; } Task MoveNext(); } Can await Rx defines Query Operators

DEMO Rx support for C# and VB “await”

Where Execution Happens – Introducing Schedulers Rx’s unified way to introduce concurrency IEnumerable IObservable SynchronousAsynchronous ToObservable ToEnumerable interface IScheduler { DateTimeOffset Now { get; } IDisposable Schedule (T state, Func action); IDisposable Schedule (T state, TimeSpan dueTime, Func action); IDisposable Schedule (T state, DateTimeOffset dueTime, Func action); }

Imported TextBox TextChanged event Asynchronous web service call Use of scheduler to synchronize res.ObserveOn(new ControlScheduler(frm)).Subscribe(words => { lst.Items.Clear(); lst.Items.AddRange((from word in words select word.Word).ToArray()); }); res.Subscribe(words => { lst.Items.Clear(); lst.Items.AddRange((from word in words select word.Word).ToArray()); }); Indicates where things run IScheduler Specifies Where Things Happen var res = from word in input.DistinctUntilChanged().Throttle(TimeSpan.FromSeconds(0.5)) from words in lookup(word) select words;

Baked in notion of “where”? foreach (var p in res.RemoteOn(new SqlScheduler(“server”))) // Process product Decoupled “what” from “where” Entry-point for the schema Custom schedulers could be very rich (e.g. server farm) IScheduler Parameterization var ctx = new NorthwindDataContext(); var res = from product in ctx.Products where product.Price > 100m select product.Name;

Expression Tree Remoting Rx.NET RxJS stocks.Where(function (t) { return t.Symbol == “MSFT”; }).Select(function (t) { return t.Quote; }) JSON serializer Observable data source Retargeting to AJAX from ticker in stocks where ticker.Symbol == “MSFT” select ticker.Quote

DEMO Remoting of Query Expressions

LINQ to the Unexpected Model[ Decisions[Reals, SA, VZ], Goals[ Minimize[20 * SA + 15 * VZ] ], Constraints[ C1 -> 0.3 * SA * VZ >= 2000, C2 -> 0.4 * SA * VZ >= 1500, C3 -> 0.2 * SA * VZ >= 500, C4 -> SA <= 9000, C5 -> VZ <= 6000, C6 -> SA >= 0, C7 -> VZ >= 0 ] from m in ctx.CreateModel(new { vz = default(double), sa = default(double) }) where 0.3 * m.sa * m.vz >= 2000 && 0.4 * m.sa * m.vz >= 1500 && 0.2 * m.sa * m.vz >= 500 where 0 <= m.sa && m.sa <= 9000 && 0 <= m.vz && m.vz <= 6000 orderby 20 * m.sa + 15 * m.vz select m To compute call Solve Non-persistent Cost / barrel Max # barrels Max # barrels Min # barrels Min # barrels Refinement %

LINQ to the Unexpected from costSA in GetPriceMonitor("SA") from costVZ in GetPriceMonitor("VZ") from m in ctx.CreateModel( new { vz = default(double), sa = default(double) }) where 0.3 * m.sa * m.vz >= 2000 && 0.4 * m.sa * m.vz >= 1500 && 0.2 * m.sa * m.vz >= 500 where 0 <= m.sa && m.sa <= 9000 && 0 <= m.vz && m.vz <= 6000 orderby costSA * m.sa + costVZ * m.vz select m Observable data sources SelectMany Parameters to decision Subscribe here!

DEMO Theorem Solving using Z3

A Futuristic Perspective Censored Next 5 years Rx and Ix are here Remoting Async Solvers Toolkits Scheduler

Stay up to date with MSDN Belux Register for our newsletters and stay up to date: Technical updates Event announcements and registration Top downloads Follow our blog Join us on Facebook LinkedIn: Download MSDN/TechNet Desktop Gadget

TechDays 2011 On-Demand Watch this session on-demand via Channel9 Download to your favorite MP3 or video player Get access to slides and recommended resources by the speakers

THANK YOU