EF – BeginTransaction Tutorial
Step 1. Create the new interface class files and the new repository class file. These files include the CRUD method. Remember the interface class files and the repository class files use the generic type description. The new interface class file name sets “ITransactionRepository.” The new repository class file name sets “TransactionRepository.”
In the new interface class file, adding the CRUD methods.
public interface ITransactionRepository<T> where T : class
{
/// <summary>
/// GetAll
/// </summary>
/// <returns>IEnumerable<T></returns>
Task<IEnumerable<T>> GetAll();
/// <summary>
/// Get information by ID
/// </summary>
/// <param name="id">int32</param>
/// <returns></returns>
Task<T> GetById(int id);
/// <summary>
/// Create new data
/// </summary>
/// <param name="entity">entity model class</param>
/// <returns></returns>
Task Create(T entity);
/// <summary>
/// Update data
/// </summary>
/// <param name="entity">entity model class</param>
/// <returns></returns>
Task Update(T entity);
/// <summary>
/// Delete data
/// </summary>
/// <param name="entity">entity model class</param>
/// <returns></returns>
Task Delete(T entity);
} Step 2. Edit the CRUD methods in the repository class file.
Note: If you want to see the complete source code, please go to my Github – Enterprise_MVC_WebApp. My Github link puts on my profile page.
Step 3. Create the view files under the web project’s Views folder. Create the new controller files under the Controller folder. New controller file name sets “TransactionController.”
Note: If you want to know how to create these files, please follow the “Building MVC pattern project by Visual Studio 2017 ( ASP.Net Core Part ).”
Step 4. Add the repository’s interface class in the controller files and other page’s ActionResult method source code.
Note: If you don’t know how to add the generic type interface class in the controller files or how to use the generic type interface class file, please follow the “Generic Type in Repository – .NET Core Part.“
Step 5. Add the AOP in a controller file. All of ActionResult add the AOP mechanism.
Note: If you don’t know how to create the aspect-oriented programming in .NET core case, please follow the “Aspect-oriented programming in .NET Core.“
Step 6. Turn on the MS SQL profiler, then run the MS SQL profiler and the web application project under the debug model. Remember a thing that doesn’t close the MS SQL profiler windows.
Step 7. The MS SQL profiler will show all trace events when you click any button or load the initial page. It can let the developer understand the web application running logic between the web application and the MS SQL.
The single-responsibility principle (SRP) is a computer-programming principle that states that every module, class or…
Command query responsibility segregation (CQRS) generalizes CQS to message-driven and event-driven architectures: it applies the CQS…
Domain-driven design (DDD) is a software design approach focusing on modelling software to match a…
A microservice architecture – a variant of the service-oriented architecture (SOA) structural style – arranges…
The Repository pattern and Unit of Work pattern are used together in most time. Unit…
Visitor – It allows the program changes the algorithm and the operations that base on the visitor…