SlideShare une entreprise Scribd logo
1  sur  12
Road of Linqulien


@yone64 で Twitterやってたりします。
 ←こんなアイコン



よく、「めとべや」とかに出没しています。
◦ 1月にWPFで何かやるらしいよ~(宣伝


メトロってなんだったんだろう…


LINQは次の2種類のデータソースを対象としてい
る
◦ IEnumerable<T>
 主にオンメモリのデータソースを表すInterface
 LINQ to Object, LINQ to XML

◦ IQueryable<T>
 主に外部のデータソースを表すInterface
 LINQ to SQL, LINQ to Entity

◦ 番外:IObservable<T>
 Reactive Extentions
 ↑今回は扱いません <(_ _)>


オンメモリのデータに対し、各データを列挙しな
がら、プログラムで評価していく手法。
◦ 通常は、System.Linq.Enumerableクラスに定義されて
いる拡張メソッド群を利用し、IEnumerable<T>を実装
するデータソースに対し評価を行う。
◦ このあたりは、この後の@neueccさんのセッションで詳
しく聞けるに違いない。
 (o゚▽゚)o 期待


外部のデータソースに対して、各データソースの
問い合わせ言語を用いて問い合わせをおこなう
◦ 通常は、System.Linq.Queryableクラスに定義されてい
る拡張メソッド群を利用し、IQueryable<T>を実装す
るデータソースに対し評価を行う。



例えば、LINQ to SQLだと
◦ C#(ラムダ式)で書かれた問合せ条件を、SQLに変換す
る
◦ DB対しSQLを発行し問合せを行う
◦ 問合せの結果をオブジェクトに詰め返却する


IQueryable<T>
◦ データソース自体を表すインターフェース
◦ IQueryProviderとExpressionをメンバとして持つ



IQueryProvider,IQueryProvider<T>
◦ データソースに対し、問合せを行う本体。
◦ 通常、LINQの利用者は意識しない。
◦ CreateQueryとExecuteをメンバをとして持つ


Expression
◦ C#の構文をデータ構造として保持するためのクラス群
◦ ラムダ式からExpressionへの変換はコンパイラが行う



System.Linq.Queryable
◦ IQueryable<T>に対する操作を行う拡張メソッド群を
定義している
◦ 各拡張メソッドでは、IQueryProvider.CreateQueryを
利用し、IQueryable<T>を生成する。



C# の構文をデータ構造として、保持する仕組み
コンパイル時に、ラムダ式から変換される。
Expression<Func<int,Bool>>
┗Parameters
ParameterExpression
┗Name :
a
┗Type :
int


┗Body
BinaryExpression
┗Left
ParameterExpression
┗Name :
a
┗Type :
int
┗Right
ConstantExpression
┗Value :
10
┗Type :
int
┗NodeType : GreaterThan
┗Type : bool
┗ReturnType : bool

ラムダ式から左図のような
構造のExpression Tree が
作成される


LINQを利用してATNDにアクセスしてみる
◦ LINQ to ATND


内部データ・外部データを意識することなく、統
一された記法でコーディングが可能。
◦ とはいえ、アルゴリズム的には意識せずに組むわけには
いかない



外部クエリのコンパイル時検証が可能
◦ とはいえ、全て検証出来るわけではなく、実行時エラー
になることも



カスタムプロバイダの作成も可能
◦ ちゃんとした物を作るのは、ちょーめんどい


チュートリアル : IQueryable LINQ プロバイダの作成
◦ http://msdn.microsoft.com/jajp/library/bb546158(v=vs.90).aspx#fbid=4gWozV-bKl9



LINQ: Building an IQueryable provider series
◦ http://blogs.msdn.com/b/mattwar/archive/2008/11/18
/linq-links.aspx



式ツリー
◦ http://msdn.microsoft.com/jajp/library/bb397951.aspx



C#たんっ!:2種類のLINQ
◦ http://csharptan.wordpress.com/2011/12/09/2%E7%A8
%AE%E9%A1%9E%E3%81%AElinq/

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

もう一つのLINQ ~ Queryable入門