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

  • GitHub Previews Agentic AI in VS Code Copilot

    GitHub announced a raft of improvements to its Copilot AI in the Visual Studio Code editor, including a new "agent mode" in preview that lets developers use the AI technology to write code faster and more accurately.

  • Copilot Engineering in the Cloud with Azure and GitHub

    Who better to lead a full-day deep dive into this tech than two experts from GitHub, which introduced the original "AI pair programmer" and spawned the ubiquitous Copilot moniker?

  • Uno Platform Wants Microsoft to Improve .NET WebAssembly in Two Ways

    Uno Platform, a third-party dev tooling specialist that caters to .NET developers, published a report on the state of WebAssembly, addressing some shortcomings in the .NET implementation it would like to see Microsoft address.

  • Random Neighborhoods Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the random neighborhoods regression technique, where the goal is to predict a single numeric value. Compared to other ML regression techniques, advantages are that it can handle both large and small datasets, and the results are highly interpretable.

  • As Some Orgs Restrict DeepSeek AI Usage, Microsoft Offers Models and Dev Guidance

    While some organizations are restricting employee usage of the new open source DeepSeek AI from a Chinese company due to data collection concerns, Microsoft has taken a different approach.

Subscribe on YouTube

Upcoming Training Events