Rainer StropekCustom Odata Providers
Introduction• You all know what OData is?  – Short demo to introduce OData?• You are all familiar with LINQ &  IQueryable?...
What is the basic idea of OData and IQueryable regarding databasequeries?ARCHITECTURE
Architecture of C#, OData and IQueryableCompiler                                             Generator              Gramma...
Architecture of C#, OData and IQueryable              C# Compiler                    BCL    C#                            ...
Typical ArchitectureClients     Load           Balancer                                  DB Failover                      ...
Solution = Sharding Clients    Load           Balancer                                      DB Load                      W...
How can we build a custom IQueryable?CUSTOM IQUERYABLE
Custom IQueryable• Use IQToolkit if possible• Derive your implementation from QueryProvider• Implement two virtual methods...
Using Custom IQueryable• Expression tree is received by query  provider• We have to rewrite and run it to all e.g.  shardi...
Implement Queryable• Use .NET‘s visitor pattern to examine and rewrite  expression tree• AnalyzeQueryVisitor   – Verifies ...
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 ...
Workflow for OData Query(simplified)               Get metdata                 service                Get query           ...
IDataServiceMetadataProvider• ResourceSet consisting of ResourceType objects (=entity types)• CustomDataServiceMetadataPro...
IDataServiceMetadataProviderpublic interface IDataServiceMetadataProvider{                                                ...
IDataServiceQueryProvider• Provides root IQueryable for a given  resource set• CustomDataServiceProvider is a simple  gene...
IDataServiceQueryProviderpublic interface IDataServiceQueryProvider{     object CurrentDataSource { get; set; }     bool I...
Linking Custom OData & Custom LINQ Provider
Further Readinghttp://www.software-architects.com
Upcoming SlideShare
Loading in …5
×

BASTA 2013: Custom OData Provider

2,208 views

Published on

Im zweiten Teil seiner OData Session zeigt Rainer Stropek, wie man eigene OData-Provider entwickelt. In einem durchgängigen Beispiel demonstriert er, wie man erst einen LINQ-Provider und darauf aufbauend einen OData-konformen REST Service erstellt und von verschiedenen Programmiersprachen und Tools darauf zugreift. In der Session werden Grundkenntnisse von OData und LINQ vorausgesetzt.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,208
On SlideShare
0
From Embeds
0
Number of Embeds
1,657
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

BASTA 2013: Custom OData Provider

  1. 1. Rainer StropekCustom Odata Providers
  2. 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. 3. What is the basic idea of OData and IQueryable regarding databasequeries?ARCHITECTURE
  4. 4. Architecture of C#, OData and IQueryableCompiler Generator Grammar rules Tree Source Lexer, Parser Generator Target (Syntax Tree) Interpreter
  5. 5. Architecture of C#, OData and IQueryable C# Compiler BCL C# IL Expression TreeOData Query (URI) SQL OData Entity runtime Framework Interpret or rewrite
  6. 6. Typical ArchitectureClients Load Balancer DB Failover Web Farm Cluster Cloud
  7. 7. Solution = Sharding Clients Load Balancer DB Load Web Farm Balancing Cluster of Failover Cloud Clusters
  8. 8. How can we build a custom IQueryable?CUSTOM IQUERYABLE
  9. 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. 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. 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. 12. How can we build a custom OData provider?CUSTOM ODATA PROVIDER
  13. 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. 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. 15. IDataServiceMetadataProvider• ResourceSet consisting of ResourceType objects (=entity types)• CustomDataServiceMetadataProvider is a simple generic implementation of IDataServiceMetadataProvider
  16. 16. IDataServiceMetadataProviderpublic 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. 17. IDataServiceQueryProvider• Provides root IQueryable for a given resource set• CustomDataServiceProvider is a simple generic implementation of IDataServiceQueryProvider
  18. 18. IDataServiceQueryProviderpublic 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. 19. Linking Custom OData & Custom LINQ Provider
  20. 20. Further Readinghttp://www.software-architects.com

×