Database Management System Project for the DBMS course.
Developed in .NET Framework 4.8, using SQL Server and Dapper NuGet.
Because it is “King of Micro ORM” in terms of speed and performance. Also, it is developed by Stack Overflow developers and doesn’t going anywhere any time soon.
Implementation is relatively simple than Entity Framework and ADO.NET for a small project. It can work after three-step process:
Queries can be called using stored procedures. Stored procedures are stored in the database and they save time and memory.
Also, provides some level of protection for SQL injection. More information available on https://dapper-tutorial.net/. And I would like to thank Tim Corey for his wonderful tutorials about database, Dapper and C# in general.
public List<Movie> GetMovie(string title)
{
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("MovieDatabaseDB")))
{
var movieList = connection.Query<Movie>("Movie_ViewAllOrSearchByTitle @Title",
new { Title = title }).ToList();
return movieList;
}
}
SQL queries can also executed with connection.Execute(SQLQuery)
after connection is established.
In this code block Dapper’s Query method is used to select id. And Execute method is used to insert selected values.
string selectMovieId = "SELECT Id FROM Movies WHERE Title = '" + movieTitle + "';";
var selectedMovieId = connection.Query<Movie>(selectMovieId).FirstOrDefault();
string insertToMovieGenres = "INSERT INTO MovieGenres(MovieId, GenreId) VALUES ( "
+ selectedMovieId.Id + "," + genreId + ");";
connection.Execute(insertToMovieGenres);
![er-diagram][schema]
[schema]:images/Schema Diagram Movie Town.png “schema”