SqLiteGenericRepository 1.0.8
dotnet add package SqLiteGenericRepository --version 1.0.8
NuGet\Install-Package SqLiteGenericRepository -Version 1.0.8
<PackageReference Include="SqLiteGenericRepository" Version="1.0.8" />
paket add SqLiteGenericRepository --version 1.0.8
#r "nuget: SqLiteGenericRepository, 1.0.8"
// Install SqLiteGenericRepository as a Cake Addin
#addin nuget:?package=SqLiteGenericRepository&version=1.0.8
// Install SqLiteGenericRepository as a Cake Tool
#tool nuget:?package=SqLiteGenericRepository&version=1.0.8
SqliteRepository
Straightforward CRUD repository for Sqlite
The main purpose of SqliteRepository is to provide an as easy as possible DAL for services using Sqlite without tinkering.
How to use it
Add your connection string to appsettings.json
{
"SQLiteDbOptions": {
"DatabaseFilename": "YourDatabaseName.db3",
"DatabaseLocation": "C:/your/database/directory"
}
}
Then add an entity which implements IEntity<int> which basically means it has an ID field with PrimaryKey and AutoIncrement attributes.
public class WeatherForecast : IEntity<int>
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
//...
}
For each entity you need a repository which implements IReadWriteRepository<TEntity, int>. It is possible to add your own methods to the repository and of course to override the default ones.
public interface IWeatherForecastRepository : IReadWriteRepository<WeatherForecast, int>
{
Task<IList<WeatherForecast>> GetAllWeatherForecastsWith16Degree();
}
public class WeatherForecastSqliteRepository : ReadWriteRepository<WeatherForecast, int>, IWeatherForecastRepository
{
public WeatherForecastSqliteRepository(IOptions<SQLiteDbOptions> sqlLiteOptions) : base(sqlLiteOptions)
{
}
public async Task<IList<WeatherForecast>> GetAllWeatherForecastsWith16Degree()
{
return await Table
.Where(x=> x.TemperatureC == 16)
.ToListAsync();
}
}
Last thing to do is to inject your connectionstring and the repository
services.Configure<SQLiteDbOptions>(Configuration.GetSection("SQLiteDbOptions"));
services.AddScoped<IWeatherForecastRepository, WeatherForecastRepository>();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.Extensions.Options (>= 7.0.1)
- sqlite-net-pcl (>= 1.8.116)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
added null/empty catch on AddRange