SlideShare a Scribd company logo
Rainer Stropek


Custom Odata Providers
Introduction
• You all know what OData is?
  – Short demo to introduce OData?


• You are all familiar with LINQ &
  IQueryable?
  – Short demo to introduce IQueryable?
What is the basic idea of OData and IQueryable regarding database
queries?

ARCHITECTURE
Architecture of C#, OData and IQueryable

Compiler
                                             Generator
              Grammar
                                               rules



                                 Tree
    Source   Lexer, Parser                   Generator   Target
                             (Syntax Tree)




                               Interpreter
Architecture of C#, OData and IQueryable

              C# Compiler                    BCL


    C#                                                 IL



                            Expression
                               Tree


OData Query
  (URI)                                                SQL

                 OData                        Entity
                runtime                    Framework



                            Interpret or
                              rewrite
Typical Architecture




Clients     Load
           Balancer



                                  DB Failover
                      Web Farm     Cluster

                          Cloud
Solution = Sharding




 Clients    Load
           Balancer


                                      DB Load
                      Web Farm    Balancing Cluster
                                     of Failover
                          Cloud       Clusters
How can we build a custom IQueryable?

CUSTOM IQUERYABLE
Custom IQueryable
• Use IQToolkit if possible
• Derive your implementation from
 QueryProvider
• Implement two virtual methods
  – object Execute(Expression expression)
  – string GetQueryText(Expression expression)
   (Optional)
Using Custom IQueryable




• Expression tree is received by query
  provider
• We have to rewrite and run it to all e.g.
  sharding databases
Implement Queryable
• Use .NET‘s visitor pattern to examine and rewrite
  expression tree
• AnalyzeQueryVisitor
   – Verifies that query is ok (e.g. must contain top-clause,
     etc.)
   – Stores reference to e.g. Take and Skip clauses
How can we build a custom OData provider?

CUSTOM ODATA PROVIDER
Custom OData Building Blocks
• Derive from DataService<T>
  – Main entry point for developing a WCF Data Service
• Implement IServiceProvider to provide...
  – ...IDataServiceMetadataProvider
     • Build custom metadata
     • Build OData metadata with e.g. reflection
  – ... IDataServiceQueryProvider
     • Provide an underlying IQueryable for query execution
Workflow for OData Query
(simplified)




               Get metdata
                 service
                Get query
                provider

                       Create data-
                         source

                                 Set current
                                 data source

                        Initialize
                         service                         Get IQueryable
                                                         used for getting   Provide
                                      Resolve resource        data          metdata
                                            set

                                Get query
                             root (IQueryable)
IDataServiceMetadataProvider

• ResourceSet consisting of ResourceType
 objects (=entity types)
• CustomDataServiceMetadataProvider is a
 simple generic implementation of
 IDataServiceMetadataProvider
IDataServiceMetadataProvider
public interface IDataServiceMetadataProvider
{
                                                         Service Ops not
     string ContainerName { get; }                        covered here
     string ContainerNamespace { get; }

    IEnumerable<ResourceSet> ResourceSets { get; }
    IEnumerable<ServiceOperation> ServiceOperations { get; }
    IEnumerable<ResourceType> Types { get; }

    IEnumerable<ResourceType> GetDerivedTypes(ResourceType resourceType);
    ResourceAssociationSet GetResourceAssociationSet(
         ResourceSet resourceSet, ResourceType resourceType,
         ResourceProperty resourceProperty);
    bool HasDerivedTypes(ResourceType resourceType);
    bool TryResolveResourceSet(string name, out ResourceSet resourceSet);
    bool TryResolveResourceType(string name, out ResourceType resourceType);
    bool TryResolveServiceOperation(string name,
         out ServiceOperation serviceOperation);
}
IDataServiceQueryProvider

• Provides root IQueryable for a given
  resource set
• CustomDataServiceProvider is a simple
  generic implementation of
 IDataServiceQueryProvider
IDataServiceQueryProvider
public interface IDataServiceQueryProvider
{
     object CurrentDataSource { get; set; }
     bool IsNullPropagationRequired { get; }

    object GetOpenPropertyValue(object target, string propertyName);
    IEnumerable<KeyValuePair<string, object>> GetOpenPropertyValues(
         object target);
    object GetPropertyValue(object target,
         ResourceProperty resourceProperty);
    IQueryable GetQueryRootForResourceSet(ResourceSet resourceSet);
    ResourceType GetResourceType(object target);
    object InvokeServiceOperation(ServiceOperation serviceOperation,
         object[] parameters);
}
Linking Custom OData & Custom LINQ Provider
Further Reading

http://www.software-architects.com

More Related Content

PPTX
The CoFX Data Model
PDF
Spring data requery
PDF
Requery overview
PDF
Alternatives of JPA/Hibernate
PPTX
Demystifying Oak Search
PDF
JavaFX and Scala in the Cloud: Stephen Chin
PPTX
WPF and Prism 4.1 Workshop at BASTA Austria
PPTX
Omnisearch in AEM 6.2 - Search All the Things
The CoFX Data Model
Spring data requery
Requery overview
Alternatives of JPA/Hibernate
Demystifying Oak Search
JavaFX and Scala in the Cloud: Stephen Chin
WPF and Prism 4.1 Workshop at BASTA Austria
Omnisearch in AEM 6.2 - Search All the Things

What's hot (20)

PPT
55 New Features in Java 7
PDF
Squeak DBX
PPT
Hibernate
PPTX
JavaFX and Scala in the Cloud
PPTX
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
PDF
Create custom looping procedures in sql server 2005 tech republic
PDF
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
PDF
Multithreading and Parallelism on iOS [MobOS 2013]
PDF
Clojure - An Introduction for Java Programmers
PDF
Java Future S Ritter
PDF
Connect 2016-Move Your XPages Applications to the Fast Lane
PPTX
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
PDF
Scala @ TechMeetup Edinburgh
PPTX
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
PPTX
Mastering the Sling Rewriter
KEY
The Why and How of Scala at Twitter
PDF
Ajax tutorial
PDF
Objective-C Is Not Java
PDF
Kotlin talk
55 New Features in Java 7
Squeak DBX
Hibernate
JavaFX and Scala in the Cloud
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
Create custom looping procedures in sql server 2005 tech republic
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
Multithreading and Parallelism on iOS [MobOS 2013]
Clojure - An Introduction for Java Programmers
Java Future S Ritter
Connect 2016-Move Your XPages Applications to the Fast Lane
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
Scala @ TechMeetup Edinburgh
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
Mastering the Sling Rewriter
The Why and How of Scala at Twitter
Ajax tutorial
Objective-C Is Not Java
Kotlin talk
Ad

Similar to BASTA 2013: Custom OData Provider (20)

PPTX
Practical OData
PPTX
05 entity framework
PPTX
Producing an OData feed in 10 minutes
PPTX
Building nTier Applications with Entity Framework Services (Part 2)
PPTX
Visual Studio LightSwitch
PDF
Visualizing content in metadata stores
PDF
Mike Taulty MIX10 Silverlight 4 Patterns Frameworks
PDF
WCF Data Services - Office Business Application &amp; iPhone
PPTX
CodeMash 2013 Microsoft Data Stack
DOC
10265 developing data access solutions with microsoft visual studio 2010
PDF
70487.pdf
PPTX
Building RESTfull Data Services with WebAPI
PPTX
Building nTier Applications with Entity Framework Services (Part 2)
PPTX
RESTful Data Services with the ADO.NET Data Services Framework
PDF
Model Driven Architecture (MDA): Motivations, Status & Future
PPTX
Social Photos - My presentation at Microsoft Tech Day
PPTX
Mike Taulty OData (NxtGen User Group UK)
PPTX
Entity Framework Today (May 2012)
PPT
Ado.Net Data Services (Astoria)
PPTX
Building data centric applications for web, desktop and mobile with Entity Fr...
Practical OData
05 entity framework
Producing an OData feed in 10 minutes
Building nTier Applications with Entity Framework Services (Part 2)
Visual Studio LightSwitch
Visualizing content in metadata stores
Mike Taulty MIX10 Silverlight 4 Patterns Frameworks
WCF Data Services - Office Business Application &amp; iPhone
CodeMash 2013 Microsoft Data Stack
10265 developing data access solutions with microsoft visual studio 2010
70487.pdf
Building RESTfull Data Services with WebAPI
Building nTier Applications with Entity Framework Services (Part 2)
RESTful Data Services with the ADO.NET Data Services Framework
Model Driven Architecture (MDA): Motivations, Status & Future
Social Photos - My presentation at Microsoft Tech Day
Mike Taulty OData (NxtGen User Group UK)
Entity Framework Today (May 2012)
Ado.Net Data Services (Astoria)
Building data centric applications for web, desktop and mobile with Entity Fr...
Ad

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Electronic commerce courselecture one. Pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Empathic Computing: Creating Shared Understanding
PDF
KodekX | Application Modernization Development
PDF
Approach and Philosophy of On baking technology
PDF
Modernizing your data center with Dell and AMD
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The AUB Centre for AI in Media Proposal.docx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Electronic commerce courselecture one. Pdf
Unlocking AI with Model Context Protocol (MCP)
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Big Data Technologies - Introduction.pptx
NewMind AI Monthly Chronicles - July 2025
Empathic Computing: Creating Shared Understanding
KodekX | Application Modernization Development
Approach and Philosophy of On baking technology
Modernizing your data center with Dell and AMD
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Weekly Chronicles - August'25 Week I
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

BASTA 2013: Custom OData Provider

  • 2. Introduction • You all know what OData is? – Short demo to introduce OData? • You are all familiar with LINQ & IQueryable? – Short demo to introduce IQueryable?
  • 3. What is the basic idea of OData and IQueryable regarding database queries? ARCHITECTURE
  • 4. Architecture of C#, OData and IQueryable Compiler Generator Grammar rules Tree Source Lexer, Parser Generator Target (Syntax Tree) Interpreter
  • 5. Architecture of C#, OData and IQueryable C# Compiler BCL C# IL Expression Tree OData Query (URI) SQL OData Entity runtime Framework Interpret or rewrite
  • 6. Typical Architecture Clients Load Balancer DB Failover Web Farm Cluster Cloud
  • 7. Solution = Sharding Clients Load Balancer DB Load Web Farm Balancing Cluster of Failover Cloud Clusters
  • 8. How can we build a custom IQueryable? CUSTOM IQUERYABLE
  • 9. Custom IQueryable • Use IQToolkit if possible • Derive your implementation from QueryProvider • Implement two virtual methods – object Execute(Expression expression) – string GetQueryText(Expression expression) (Optional)
  • 10. Using Custom IQueryable • Expression tree is received by query provider • We have to rewrite and run it to all e.g. sharding databases
  • 11. Implement Queryable • Use .NET‘s visitor pattern to examine and rewrite expression tree • AnalyzeQueryVisitor – Verifies that query is ok (e.g. must contain top-clause, etc.) – Stores reference to e.g. Take and Skip clauses
  • 12. How can we build a custom OData provider? CUSTOM ODATA PROVIDER
  • 13. Custom OData Building Blocks • Derive from DataService<T> – Main entry point for developing a WCF Data Service • Implement IServiceProvider to provide... – ...IDataServiceMetadataProvider • Build custom metadata • Build OData metadata with e.g. reflection – ... IDataServiceQueryProvider • Provide an underlying IQueryable for query execution
  • 14. Workflow for OData Query (simplified) Get metdata service Get query provider Create data- source Set current data source Initialize service Get IQueryable used for getting Provide Resolve resource data metdata set Get query root (IQueryable)
  • 15. IDataServiceMetadataProvider • ResourceSet consisting of ResourceType objects (=entity types) • CustomDataServiceMetadataProvider is a simple generic implementation of IDataServiceMetadataProvider
  • 16. IDataServiceMetadataProvider public interface IDataServiceMetadataProvider { Service Ops not string ContainerName { get; } covered here string ContainerNamespace { get; } IEnumerable<ResourceSet> ResourceSets { get; } IEnumerable<ServiceOperation> ServiceOperations { get; } IEnumerable<ResourceType> Types { get; } IEnumerable<ResourceType> GetDerivedTypes(ResourceType resourceType); ResourceAssociationSet GetResourceAssociationSet( ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty); bool HasDerivedTypes(ResourceType resourceType); bool TryResolveResourceSet(string name, out ResourceSet resourceSet); bool TryResolveResourceType(string name, out ResourceType resourceType); bool TryResolveServiceOperation(string name, out ServiceOperation serviceOperation); }
  • 17. IDataServiceQueryProvider • Provides root IQueryable for a given resource set • CustomDataServiceProvider is a simple generic implementation of IDataServiceQueryProvider
  • 18. IDataServiceQueryProvider public interface IDataServiceQueryProvider { object CurrentDataSource { get; set; } bool IsNullPropagationRequired { get; } object GetOpenPropertyValue(object target, string propertyName); IEnumerable<KeyValuePair<string, object>> GetOpenPropertyValues( object target); object GetPropertyValue(object target, ResourceProperty resourceProperty); IQueryable GetQueryRootForResourceSet(ResourceSet resourceSet); ResourceType GetResourceType(object target); object InvokeServiceOperation(ServiceOperation serviceOperation, object[] parameters); }
  • 19. Linking Custom OData & Custom LINQ Provider