Creating an HTTP Service with Web API: Listing 3

Modified code for OData query.

Imports System.ServiceModel
Imports System.ServiceModel.Web
Imports CarInventory.Inventory.Resources
Imports System.Linq  'Used for OData Support

Namespace Inventory.APIs

    <ServiceContract()>
    Public Class InventoryAPI

        <WebGet(UriTemplate:="")> _
        Public Function [Get]() As IQueryable(Of InventoryDTO)  'Using IQueryable allows for OData Support 
            'Public Function [Get]() As IEnumerable(Of InventoryDTO)
            Dim InventoryList = New List(Of InventoryDTO)() From { _
             New InventoryDTO() With {.Id = 1, .Year = 2012, .Make = "Cheverolet", .Model = "Corvette", .Color =
               "Red", .Quantity = 2},
             New InventoryDTO() With {.Id = 2, .Year = 2011, .Make = "Ford", .Model = "Mustang GT", .Color = 
               "Silver", .Quantity = 8},
             New InventoryDTO() With {.Id = 3, .Year = 2008, .Make = "Mercedes-Benz", .Model = "C300", .Color = 
               "Black", .Quantity = 5},
             New InventoryDTO() With {.Id = 4, .Year = 2010, .Make = "Dodge", .Model = "Charger", .Color = 
               "Blue", .Quantity = 7} _
            }
            Return InventoryList.AsQueryable   'Using AsQueryable allows for OData Support
        End Function

    End Class
End Namespace

About the Author

Sam Nasr has been a software developer since 1995, focusing mostly on Microsoft technologies. Having achieved multiple certifications from Microsoft (MCAD, MCTS(MOSS), and MCT), Sam develops, teaches, and tours the country to present various topics in .Net Framework. He is also actively involved with the Cleveland C#/VB.Net User Group, where he has been the group leader since 2003. In addition, he also started the Cleveland WPF Users Group in June 2009, and the Cleveland .Net Study Group in August 2009, and is the INETA mentor for Ohio. When not coding, Sam loves spending time with his family and friends or volunteering at his local church. He can be reached by email at [email protected]

comments powered by Disqus

Featured

  • Microsoft's New Programming Language for Excel Now Turing Complete

    Microsoft, which calls its Excel spreadsheet a programming language, reports that an effort called LAMBDA to make it even more of a programming language is paying off, recently being deemed Turing complete.

  • New Visual Studio Razor Editor 'Close to Being Ready' for Blazor and Other Projects

    The experimental Razor editor for Visual Studio introduced last summer has been updated and is "close to being ready for normal daily development."

  • Microsoft Updates 'Must Have' Xamarin Community Toolkit

    The Xamarin Community Toolkit provides all kinds of effects, views and helpers to complement mobile app development with Microsoft's recently released, open source, cross-platform Xamarin.Forms 5.

  • JetBrains Unveils Plans for WinForms, WPF and More in Rider .NET IDE

    JetBrains announced plans for Windows Forms, Windows Presentation Foundation (WPF), ASP.NET and more tooling in the next release of its popular Rider IDE for .NET development.

Upcoming Events