1 / 24

.NET Harmony

.NET Harmony. A look into efficiencies with EF Code First, Web API, & OData. Introduction. Travis Gosselin Senior Solutions Architect @ ToolBox Solutions Inc. 7 Years Development Experience in .NET Enjoy Working in the Full Stack of .NET

lela
Download Presentation

.NET Harmony

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. .NET Harmony A look into efficiencies with EF Code First, Web API, & OData

  2. Introduction Travis Gosselin Senior Solutions Architect @ ToolBox Solutions Inc. 7 Years Development Experience in .NET Enjoy Working in the Full Stack of .NET … but I do have a special place in my heart specifically for Web Development

  3. Goals & Outline • .NET Harmony • Entity Framework • MVC 4 • ASP.NET Web API • REST • OData • Entity Framework Code First • ASP.NET Web API • OData • Integration & Consumption *Focusing on concept introductions, with attention to integration & consumption.

  4. Entity Framework Introduction • Entity Framework is an ORM (Object Relational Mapper) • EF increases developer productivity by providing simple pre-generated data access components, accessible from a LINQ syntax.

  5. Entity Framework • Open Source as of EF 5 (August 2012) – Current Version • Works with any relational database • Available Types: • Database First • Model First • Code First**

  6. Entity Framework Code First • EF Code First was introduced in EF 4.1 • Gets rid of the nasty EF Designer & the need for undesirable meta data and code generation only files (they may be POCO but they don’t quite cut it in EF DB First) • Convention Over Configuration (if you want) • Limitations: • Stored Procedure Support (available in EF6) • Enumeration Support (available in EF6)

  7. DEMO: Entity Framework Code First A Simple Music Database

  8. Entity Framework Code First - Migrations

  9. ASP.NET Web API “ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework” (asp.net/web-api/). • Simply: Building pure HTTP based endpoints without hassle • MVC4 (.NET 4.5) & Nuget Packages (*Available in ASP.NET Web Forms) • Take advantage of HTTP features • Uses HTTP verbs / actions by convention (or go custom) • Makes use of pure HTTP return codes • Content Negotiation (JSON, XML, & Custom) • Model binding & formatting

  10. DEMO: ASP.NET Web API

  11. Why Web APIwith .SVC & .ASMX Around? • WCF Web API development turned into ASP.NET Web API • Provides pure HTTP endpoints for all application types (HTML5, mobile, desktop) • A conventional way for accessing data without WCF configurations & Contracts • Flexibility to create any type of web services: • RPC, CRUD, REST, OData • .SVC is still your choice on .NET 3.5 or you require SOAP based • Web API offers content negotiation • RPC vs REST? Am I doing it wrong if I’m not using REST?

  12. REST = REpresentational State Transfer • URIs – can access all components via direct URI • Uniform Interface - GET (Retrieve), POST (Create), PUT (Update), DELETE (Delete) • Stateless – No state / context between requests. • Hypermedia (links) – allows expansion and navigation • Cache-ability – certain verb types define themselves as cacheable *REST is a style, SOAP is a protocol

  13. REST = REpresentational State Transfer http://www.restapitutorial.com/lessons/httpmethods.html

  14. DEMO: ASP.NET Web API & REST

  15. OData “ODatais a standardized protocol for creating and consuming data APIs. OData builds on core protocols like HTTP and commonly accepted methodologies like REST. The result is a uniform way to expose full-featured data APIs” (odata.org). • Simply: Standardized method of accessing rich data APIs. • Open Microsoft Initiative • REST based • Provides metadata descriptions of entire API • Has its own OData querying syntax that gets used on the URI

  16. OData Query Syntax • http://service.com/simple?$orderby=Name • http://service.com/simple?$top=10 • http://service.com/simple?$skip=2 • http://service.com/simple?$filter=Name eq ‘Travis' • http://service.com/simple?$filter=substringof(‘rav', Name)

  17. DEMO: OData with Web API

  18. WCF Data Services VS Web API OData Web API OData WCF Data Services Was available here first Most complete OData Support Full Exposure of Data Stores without Business Logic No immediate Content Negotiation • Limited OData support on launch • Simple integration with custom service layers & logic • Easy to use with non-LINQ provider data • Mix OData with other Service Types • Short release cycle on updates • Extensibility • Supports most important OData features • Does not easily support hypermedia linking

  19. DEMO: WCF Data Services

  20. DEMO: Further Investigation into better OData in Web API BreezeController & EntitySetController

  21. Client Integration with OData • Use new HttpClient for Web API • What about WebClient in .NET 2.0? … HttpClient offers more flexibility to pure HTTP • WebClient is akin to ASMX as HttpClient is akin to Web API • JavaScript: Breeze, DataJS, JayData • .NET / Silverlight / Windows Phone / WinRT – WCF Data Services Client • iOS– OData4ObjC • Android – OData4j

  22. DEMO: Consumption of OData

  23. Final Thoughts • Things to investigate: • Web API Security will work with ASP.NET Authorization & Security • Web API Formatters & MediaTypeFormats Provide Ultimate Flexibility • Further investigation around the EntitySetController • Web API provides ultimate flexibility in most scenarios if you don’t require pure OData. • Simple straightforward exposure of OData from WCF Data Services if you have no business logic. • Thin slice your server code for JS Heavy SPAs by exposing your data store with OData • Web API conventions & simplicity are very attractive

  24. Deck & Examples (VS2012.2) • Available at Blog: www.travisgosselin.com/blog/?p=370 • Will be available soon on GitHub site. • Questions?

More Related