This Azure Functions project demonstrates how to use Entity Framework Core to perform CRUD operations in a serverless environment. The project includes functions to retrieve, add, update, and delete stock information using an HTTP-triggered approach.
- Azure Subscription: Ensure you have an active Azure subscription to deploy and run the Azure Functions.
-
Database Connection: Update the
ShareDataContext
class in theDataContext
folder with your database connection string.// In ShareDataContext.cs optionsBuilder.UseSqlServer("your_connection_string_here");
-
Entity Framework Migrations: If the database does not exist, you may need to apply Entity Framework migrations to create the required tables. Open a command prompt in the project directory and run the following commands:
dotnet ef migrations add InitialCreate dotnet ef database update
-
Azure Functions Configuration: Make sure to configure the Azure Functions settings, including the database connection string, in the Azure Portal or using local settings for local development.
- Endpoint:
GET
orPOST
request to the function URL. - Description: Retrieves all stock information including associated transactions from the database.
- Endpoint:
POST
request to the function URL. - Description: Adds a new stock to the database. Provide stock details in the request body as JSON.
- Endpoint:
POST
request to the function URL. - Description: Updates an existing stock in the database. Provide updated stock details in the request body as JSON.
- Endpoint:
POST
request to the function URL. - Description: Deletes an existing stock from the database. Provide the stock ID in the request body as JSON.
Local Development:
Run the project locally using Visual Studio or the func CLI. Test the functions using tools like Postman or cURL.
Publish the function app to your Azure subscription. Ensure the required configuration settings are set in the Azure Portal.
None reported.
Contributions are welcome! Please create an issue or pull request for any improvements or bug fixes.
This project is licensed under the MIT License.