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. Cathy's avatar Cathy says:

    Hi there, You have done a fantastic job. I’ll definitely digg it and for my part recommend to my friends. I’m confident they’ll be benefited from this web site.

  2. The soft-delete pattern with a deleted column is a good habit to build early in API design – it makes audit trails and data recovery much easier down the road. Primary key auto-increment on id keeps the schema clean for a dealership use case.

  3. Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  4. Can I simply say what a comfort to uncover a person that really understands what they’re talking about on the web. You actually realize how to bring an issue to light and make it important. More people need to read this and understand this side of your story. It’s surprising you aren’t more popular given that you surely possess the gift.

  5. Wow that was odd. I just wrote an really 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 wonderful blog!

  6. May I just say what a relief to find a person that actually knows what they’re talking about on the net. You actually know how to bring an issue to light and make it important. More and more people ought to read this and understand this side of the story. I was surprised that you’re not more popular since you certainly have the gift.

  7. GOGO真人's avatar GOGO真人 says:

    Wow that was odd. 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. Regardless, just wanted to say wonderful blog!

  8. Right now it appears like BlogEngine is the top blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?

  9. 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.

  10. May I just say what a relief to discover someone that truly knows what they’re talking about over the internet. You certainly realize how to bring an issue to light and make it important. More people must read this and understand this side of your story. It’s surprising you are not more popular given that you certainly possess the gift.

  11. R8彩票APP's avatar R8彩票APP says:

    At this time it appears like WordPress is the top blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?

  12. May I simply just say what a relief to find an individual who really knows what they are talking about on the net. You actually understand how to bring an issue to light and make it important. More people should look at this and understand this side of the story. I can’t believe you are not more popular since you surely possess the gift.

  13. 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.

  14. Aw, this was a very nice post. Taking a few minutes and actual effort to generate a good article… but what can I say… I put things off a whole lot and never manage to get anything done.

  15. Aw, this was an exceptionally nice post. Spending some time and actual effort to produce a great article… but what can I say… I procrastinate a whole lot and never seem to get nearly anything done.

  16. Aw, this was an exceptionally good post. Taking the time and actual effort to produce a good article… but what can I say… I procrastinate a lot and never manage to get nearly anything done.

  17. 龙腾彩票's avatar 龙腾彩票 says:

    Can I simply just say what a comfort to find somebody that actually understands what they’re talking about on the web. You actually realize how to bring a problem to light and make it important. More and more people must check this out and understand this side of the story. I can’t believe you’re not more popular since you definitely have the gift.

  18. Hi there, You have performed an incredible job. I will definitely digg it and in my view suggest to my friends. I am confident they’ll be benefited from this site.

  19. Can I just say what a comfort to discover somebody who genuinely understands what they’re discussing online. You certainly realize how to bring a problem to light and make it important. More people should read this and understand this side of your story. It’s surprising you are not more popular since you certainly possess the gift.

  20. Aw, this was an extremely good post. Taking a few minutes and actual effort to create a very good article… but what can I say… I put things off a whole lot and don’t seem to get nearly anything done.

  21. Hey there, You’ve performed an excellent job. I’ll definitely digg it and for my part recommend to my friends. I am confident they will be benefited from this site.

  22. Currently it looks like Drupal is the preferred blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog?

  23. Today, while I was at work, my sister stole my iPad and tested to see if it can survive a 40 foot drop, just so she can be a youtube sensation. My apple ipad is now destroyed and she has 83 views. I know this is completely off topic but I had to share it with someone!

  24. Just want to say your article is as amazing. The clearness in your post is just great and i could assume you’re an expert on this subject. Well with your permission allow me to grab your feed to keep up to date with forthcoming post. Thanks a million and please keep up the rewarding work.

  25. Simply wish to say your article is as amazing. The clearness in your post is simply cool and i can assume you are an expert on this subject. Well with your permission let me to grab your feed to keep updated with forthcoming post. Thanks a million and please keep up the enjoyable work.

  26. Just wish to say your article is as astounding. The clearness in your post is simply cool and i could assume you are an expert on this subject. Well with your permission allow me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please keep up the gratifying work.

  27. Excellent pieces. Keep writing such kind of information on your page. Im really impressed by your blog.

  28. At this time it seems like WordPress is the preferred blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?

  29. At this time it appears like Drupal is the best blogging platform available right now. (from what I’ve read) Is that what you are using on your blog?

  30. At this time it looks like BlogEngine is the top blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?

  31. Hey there, You have done an incredible job. I’ll certainly digg it and in my view recommend to my friends. I am sure they’ll be benefited from this website.

  32. Hey there, You have done an incredible job. I’ll certainly digg it and in my opinion recommend to my friends. I am confident they will be benefited from this site.

  33. Hey there, You’ve performed a fantastic job. I’ll certainly digg it and personally suggest to my friends. I am sure they will be benefited from this website.

  34. Hey there, You have performed a great job. I will definitely digg it and in my view suggest to my friends. I’m sure they will be benefited from this site.

  35. Hi there, You’ve done an incredible job. I’ll certainly digg it and individually recommend to my friends. I am sure they will be benefited from this website.

  36. At this time it sounds like Drupal is the top blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog?

  37. Currently it appears like Expression Engine is the top blogging platform available right now. (from what I’ve read) Is that what you are using on your blog?

  38. Cryptify Hub's avatar Cryptify Hub says:

    安全性提醒:任何导航站上的链接都存在被劫持或过期的可能性。Cryptify Hub作为网址大全会尽力维护链接的有效性,但无法做到实时监控。建议在点击关键链接后,核对浏览器地址栏的域名是否与你预期的一致。尤其是涉及私钥输入或钱包连接的页面,请格外谨慎。

  39. Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  40. peso888's avatar peso888 says:

    Hi there I am so glad I found your blog, I really found you by mistake, while I was browsing on Yahoo for something else, Nonetheless I am here now and would just like to say thank you for a marvelous post and a all round interesting blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have saved it and also included your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the great job.

  41. Thank you for the good writeup. It in reality used to be a amusement account it. Look advanced to more brought agreeable from you! However, how could we keep in touch?

  42. Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://www.binance.com/register?ref=JW3W4Y3A

  43. DavidAcrox's avatar DavidAcrox says:

    The technique used to derive CBD full spectrum cbd oil 1500mg from hemp significantly impacts the end product’s caliber. CO2 extraction is generally regarded as the benchmark because it preserves beneficial compounds without introducing unwanted solvents. Reputable brands openly share their extraction methods alongside independent lab certificates. Aware shoppers who recognize these variations make wiser purchasing selections.

Leave a Reply

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