APIs in .NET – Part 2 – The Database

As noted in part 1 of this series, I will be building an application specifically to explore building APIs. To get started, I’ll want to build a back-end database. The application we’ll be simulating is a car dealership. Customers can list a car for sale, or look through cars they might buy.

We want to keep things very simple, so we will create a single table for now: Car

Car will have six columns

  • id (int primary key)
  • make (varchar 50)
  • model (varchar 50)
  • model_year (int)
  • price (decimal)
  • deleted (int)

By marking id as primary key you ensure two things: no two cars will have the same id, and each added row will have an incremented value. The deleted column allows us to have “soft” deletes — that is, we mark a row deleted but do not remove it from the table.

We can now insert a few rows:

insert into car
(make, model, model_year, price, deleted)
values ('Subaru', 'Imprezza', 2024 ,35500, 0),
('Subaru','Outback',2024,42000, 0),
('Prius','C',2022,25000, 0)

Note: I highly recommend the book SQL Pocket Guide (O’Reilly, Alice Zhao) for looking up how to do all the SQL operations I’ll show in these blog entries.

With this table, we can create endpoints for the CRUD (Create Read Update Delete) operations and more (e.g., obtaining a list of available vehicles).

In the next post, we’ll build our first endpoint to get a list of available cars.

Unknown's avatar

About Jesse Liberty

** Note ** Jesse is currently looking for a new position. You can learn more about him at https://jesseliberty.bio Thank you. Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty was a Team Lead and Senior Software Engineer for various corporations, a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a 13 year Microsoft MVP.
This entry was posted in API, Essentials. Bookmark the permalink.

358 Responses to APIs in .NET – Part 2 – The Database

  1. Jayme Laroux's avatar Jayme Laroux says:

    Wow that was strange. I just wrote an extremely long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Regardless, just wanted to say superb blog!

  2. Greate article. Keep posting such kind of info on your blog. Im really impressed by your site.

  3. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

  4. Hey there, You’ve done a great job. I will definitely digg it and individually suggest to my friends. I am sure they’ll be benefited from this web site.

  5. Wow that was strange. I just wrote an incredibly long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say excellent blog!

  6. Judith Danz's avatar Judith Danz says:

    May I simply just say what a relief to uncover an individual who really understands what they are discussing on the net. You definitely understand how to bring an issue to light and make it important. More and more people should look at this and understand this side of the story. It’s surprising you’re not more popular because you definitely possess the gift.

  7. Hi there, You have done a fantastic job. I will definitely digg it and personally recommend to my friends. I am confident they will be benefited from this website.

  8. Shaquana's avatar Shaquana says:

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

Leave a Reply

Your email address will not be published. Required fields are marked *