Integrating Azure Functions with Dapper in C# involves combining the power of serverless computing with the simplicity of Dapper, a lightweight Object-Relational Mapping (ORM) library. This integration enables efficient and scalable database operations within serverless applications.
2. Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
Punctuality
Join the session 5 minutes prior to the session start time. We start on
time and conclude on time!
Feedback
Make sure to submit a constructive feedback for all sessions as it is very
helpful for the presenter.
Silent Mode
Keep your mobile devices in silent mode, feel free to move out of session
in case you need to attend an urgent call.
Avoid Disturbance
Avoid unwanted chit chat during the session.
3. 1. A Brief of Azure Function
2. Types of Triggers
3. What is Dapper?
4. Extension Method in Dapper
5. Nuget Packages
6. Synergy of Azure Function and Dapper
7. App Demo
4. A Brief of Azure Function
Serverless Computing: Azure Functions is a serverless computing service, allowing developers
to run code without managing infrastructure.
Event-Driven Architecture: Designed for event-driven scenarios, executing functions in
response to events or triggers.
Microservices Oriented: Supports building microservices-based applications by breaking down
functionalities into small, independent functions.
Pay-Per-Use Pricing: Cost-effective with pay-as-you-go pricing based on the actual execution of
functions.
Multi-Language Support: Allows development in various languages, including C#, JavaScript,
Python, and more.
Integration with Azure Services: Seamless integration with other Azure services, fostering a
comprehensive cloud ecosystem.
Scalability: Automatically scales based on demand, handling varying workloads efficiently.
5. Types of Triggers
HTTP Trigger: This type of function is triggered by an HTTP request. It can be used to build web
APIs and handle HTTP-based interactions.
Timer Trigger: A timer trigger executes a function on a predefined schedule or at regular
intervals. It is useful for performing tasks such as data synchronization, periodic processing, or
generating reports.
Blob Trigger: This type of function is triggered when a new or updated blob is added to an Azure
Storage container. It enables you to automate processes based on changes in storage blobs.
Queue Trigger: A queue trigger is triggered when a message is added to an Azure Storage
queue. It provides a way to process messages in a queue-based architecture, allowing you to
build event-driven applications.
Event Grid Trigger: An event grid trigger is invoked when an event is published to an Azure
Event Grid topic or domain. It enables reactive processing of events and can be used to build
event-driven architectures.
Cosmos DB Trigger: This type of function is triggered when there are changes to a document in
an Azure Cosmos DB container. It allows you to build real-time data processing and
synchronization scenarios.
6. What is Dapper?
Definition: Dapper is a lightweight, open-source Object-Relational Mapping (ORM) library for
.NET that simplifies data access while emphasizing performance and flexibility.
Micro-ORM Philosophy: Dapper is often referred to as a "micro-ORM" because it provides a
minimalistic set of features, focusing on core ORM functionality without the complexity of full-
fledged ORM frameworks.
Object-Relational Mapping (ORM): Dapper bridges the gap between relational databases and
object-oriented programming in .NET by allowing developers to map database queries to object
models seamlessly.
Stack Overflow Origins: Originally developed by the Stack Overflow engineering team, Dapper
was created to address specific performance challenges in handling large amounts of data for the
Stack Overflow website.
Open Source: Dapper is open-source, allowing developers to contribute, customize, and extend
its functionality to suit their specific project requirements.
Query Execution: Dapper optimizes query execution by using raw SQL and directly mapping
query results to objects, avoiding the overhead associated with heavier ORMs.
7. Extension Method in Dapper
Execute – an extension method that we use to execute a command one or multiple times and
return the number of affected rows
Query – with this extension method, we can execute a query and map the result
QueryFirst – it executes a query and maps the first result
QueryFirstOrDefault – we use this method to execute a query and map the first result or a
default value if the sequence contains no elements
QuerySingle – an extension method that executes a query and maps the result. It throws an
exception if there is not exactly one element in the sequence
QuerySingleOrDefault – executes a query and maps the result or a default value if the sequence
is empty. It throws an exception if there is more than one element in the sequence
QueryMultiple – an extension method that executes multiple queries within the same command
and maps results
8. Nuget Packages
Dapper Nuget package
• Dapper is a Nuget library that you can add in to your project that will enhance your
application DB connections via extension methods on your DbConnection instance.
• This provides a simple and efficient API for invoking SQL, with support for both synchronous
and asynchronous data access, and allows both buffered and non-buffered queries.
PM> Install-Package Dapper
Microsoft.Data.SqlClient
• The library include classes for establishing and managing connections to SQL Server
databases.
• It provide functionality for executing SQL queries and commands, as well as handling the
retrieval and manipulation of data.
• Support for managing transactions, which ensures that a series of database operations either
succeed as a whole or fail entirely.
PM> Install-Package Microsoft.Data.SqlClient
9. Synergy of Azure Function and Dapper
Scalability: Azure Functions provide automatic scaling, allowing your application to handle
varying workloads efficiently. Dapper's lightweight nature ensures minimal resource consumption,
contributing to the overall scalability.
Rapid Development: Dapper simplifies data access with its lightweight and easy-to-use API,
reducing the time required for development. Azure Functions facilitate serverless architecture,
enabling developers to focus on business logic without worrying about infrastructure.
Microservices Architecture: Azure Functions support microservices architecture, allowing
developers to build small, independent, and scalable components. Dapper's micro ORM
capabilities complement the microservices paradigm, providing a lightweight data access layer for
each microservice.
Serverless and Event-Driven Architecture: Azure Functions operate in a serverless
environment, eliminating the need for infrastructure management. Dapper's asynchronous
support aligns well with event-driven architectures, enhancing responsiveness and efficiency.