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

  • VS Code Java Team Details 5 Best Dev Practices

    Microsoft's Visual Studio Code team for Java development added a new Coding Pack for Java installer and detailed best practices for setting up a development environment.

  • Binary Classification Using PyTorch: Defining a Network

    Dr. James McCaffrey of Microsoft Research tackles how to define a network in the second of a series of four articles that present a complete end-to-end production-quality example of binary classification using a PyTorch neural network, including a full Python code sample and data files.

  • Blazor Debugging Boosted in .NET 5 RC 2

    In highlighting updates to ASP.NET Core in the just-launched second and final Release Candidate of .NET 5, Microsoft pointed out better debugging for Blazor, the red-hot project that allows for C# coding of web projects.

  • Block Stack

    Final Go-Live .NET 5 Release Candidate Ships Ahead of Nov. 10 Debut

    Having been deemed "feature complete" and "near final" and "go live" for some time now, .NET 5 is out in a second and final Release Candidate, scheduled for a Nov. 10 debut during .NET Conf 2020.

  • Edge Browser Dev Tools for VS Code Now Generally Available

    Microsoft has moved its Edge browser development tools for Visual Studio Code from preview to general availability, providing in-editor web site debugging and other functionality.

Upcoming Events