To be able to query or change data persistently in a database, for example.
We want to use commons.persistance to get the number and a list of all movies contained in a given database.
- Register dao with e.g. Microsoft.Extensions.DependencyInjection or simply create an instance like:
IGenericDao<Movie, int> _movieDao = new MovieDao<Movie, int>();
- Create a new class to be able to implement the dao
public class MovieDao : GenericDao<Movie, int>
{
public MovieDao(MovieContext dbContext) : base(dbContext)
{
}
}
- Now you can use the dao to get all the data
IEnumerable allMovies = movieDao.GetAll();
- Determine the number of films with the help of the Daos
public long AnzahlDerFilme()
{
return allMovies.GetCount(); //returns amount of entities
}
- include Nuget-Package (queo.commons.persistance)
<PackageReference Include="Queo.Commons.Persistence" Version="3.0.0" />
- Register the Dao
- Create a new class to be able to implement the dao
- Instantiate new Dao
- Now you can use the Dao
- If you want to use the TransactionHandling, you have to add the following inside your program.cs or startup.cs.
UseTransactionHandling <TDbContext>(this IServiceCollection services);