Best practice for getting data from a database RRS feed

  • Question

  • User1953081067 posted


    I've just completed my very first tutorial using the ASP.NET Web API here.

    In the code, this is where all products are returned:

            Product[] products = new Product[] 
                new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 }, 
                new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M }, 
                new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M } 

    I'd now like to learn how best to replace the hard coded list with a call to a database, and I'm keen to learn the 'right' way.

    I've done a fair amount with web forms (never used MVC), and am used to getting a DataView like this

                DataView dvStaffForDropDown = tbl_Staff.Select_Staff(0);
                DropDownList_Staff.DataSource = dvStaffForDropDown;

    I would really appreciate some help with linking the two.

    Thanks as always

    Saturday, April 4, 2015 12:54 PM


All replies

  • User2129316869 posted

    Carefully study the Working with Data section in that tutorial series. You can find it at http://www.asp.net/web-api/overview/data/using-web-api-with-entity-framework/part-1. It is simple with just 10 interesting steps.

    The section uses Entity framework for data access.

    Best of luck


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 4, 2015 1:06 PM
  • User1953081067 posted

    Thanks, although I've not used Entity framework, and if possible, would like to keep things simple and learn one new thing at a time.

    Is there way I can use the same (or similar) method to what I've used before?


    Saturday, April 4, 2015 1:15 PM
  • User2129316869 posted

    To be sincere with you, I completely understand what it takes to leave a tech you are used to for another but Entity Framework is really worth and the tutorial there is simple too. Just give it about 4 hrs and you will be good to go.

    Regards Richard

    Sunday, April 5, 2015 5:05 AM