![]() |
VOOZH | about |
dotnet add package WatsonORM.Sqlite --version 3.0.14
NuGet\Install-Package WatsonORM.Sqlite -Version 3.0.14
<PackageReference Include="WatsonORM.Sqlite" Version="3.0.14" />
<PackageVersion Include="WatsonORM.Sqlite" Version="3.0.14" />Directory.Packages.props
<PackageReference Include="WatsonORM.Sqlite" />Project file
paket add WatsonORM.Sqlite --version 3.0.14
#r "nuget: WatsonORM.Sqlite, 3.0.14"
#:package WatsonORM.Sqlite@3.0.14
#addin nuget:?package=WatsonORM.Sqlite&version=3.0.14Install as a Cake Addin
#tool nuget:?package=WatsonORM.Sqlite&version=3.0.14Install as a Cake Tool
| Library | Version | Downloads |
|---|---|---|
| WatsonORM (all supported database types) | 👁 NuGet Version |
👁 NuGet |
| WatsonORM.Mysql | 👁 NuGet Version |
👁 NuGet |
| WatsonORM.Postgresql | 👁 NuGet Version |
👁 NuGet |
| WatsonORM.Sqlite | 👁 NuGet Version |
👁 NuGet |
| WatsonORM.SqlServer | 👁 NuGet Version |
👁 NuGet |
| WatsonORM.Core | 👁 NuGet Version |
👁 NuGet |
WatsonORM is a lightweight and easy to use object-relational mapper (ORM) in C# for .NET Core built on top of DatabaseWrapper. WatsonORM supports Microsoft SQL Server, Mysql, MariaDB, PostgreSQL, and Sqlite databases, both on-premises and in the cloud.
Core features:
For a sample app exercising this library, refer to the Test project contained within the solution.
We'd like to give special thanks to those who have contributed or helped make the library better!
@Maclay74 @flo2000ace @MacKey-255
This example uses Sqlite. For SqlServer, Mysql, or Postgresql, you must make sure the database exists. Tables will be automatically created in this example. Refer to the Test project for a complete example.
using ExpressionTree;
using DatabaseWrapper.Core;
using Watson.ORM;
using Watson.ORM.Core;
// Apply attributes to your class
[Table("person")]
public class Person
{
[Column("id", true, DataTypes.Int, false)]
public int Id { get; set; }
[Column("firstname", false, DataTypes.Nvarchar, 64, false)]
public string FirstName { get; set; }
// Parameter-less constructor is required
public Person()
{
}
}
// Initialize
DatabaseSettings settings = new DatabaseSettings("./WatsonORM.db");
WatsonORM orm = new WatsonORM(settings);
orm.InitializeDatabase();
orm.InitializeTable(typeof(Person)); // initialize one table
orm.InitializeTables(new List<Type> { typeof(Person) }); // initialize multiple tables
// Insert
Person person = new Person { FirstName = "Joel" };
Person inserted = orm.Insert<Person>(person);
// Select
Person selected = orm.SelectByPrimaryKey<Person>(1);
// Select all records
List<Person> people = orm.SelectMany<Person>();
// Select many by column name
Expr e1 = new Expr("id", OperatorEnum.GreaterThan, 0);
people = orm.SelectMany<Person>(e1);
// Select many by property
Expr e2 = new Expr(
orm.GetColumnName<Person>(nameof(Person.Id)),
DbOperators.GreaterThan,
0);
people = orm.SelectMany<Person>(e2);
// Select many by property with pagination
// Retrieve 50 records starting at record number 10
people = orm.SelectMany<Person>(10, 50, e2);
// Select many with descending order
ResultOrder[] resultOrder = new ResultOrder[1];
resultOrder[0] = new ResultOrder("id", OrderDirectionEnum.Descending);
people = orm.SelectMany<Person>(null, null, e2, resultOrder);
// Update
inserted.FirstName = "Jason";
Person updated = orm.Update<Person>(inserted);
// Delete
orm.Delete<Person>(updated);
Columns can be named explicitly by specifying the colum name in the Column attribute constructor. Alternatively, constructors that don't include a name can be used, in which case the name of the property will be used as the column name.
Example with explicit naming:
[Column("id", true, DataTypes.Int, false)] // column name "id"
public int Id { get; set; }
[Column("firstname", false, DataTypes.Nvarchar, 64, false)] // column name "firstname"
public string FirstName { get; set; }
Example without explicit naming:
[Column(true, DataTypes.Int, false)] // column name "Id"
public int Id { get; set; }
[Column(DataTypes.Nvarchar, 64, false)] // column name "FirstName"
public string FirstName { get; set; }
SelectMany can be paginated by using the method with either signature (int? indexStart, int? maxResults, Expr expr) or (int? indexStart, int? maxResults, Expr expr, ResultOrder[] resultOrder). indexStart is the number of records to skip, and maxResults is the number of records to retrieve.
Paginated results are always ordered by the primary key column value in ascending order, i.e. ORDER BY id ASC in the Person example above.
If you wish to determine if there are any errors or warnings associated with a given Type, use either the ValidateTable or ValidateTables API:
List<string> errors = new List<string>();
List<string> warnings = new List<string>();
// validate a single table
bool success = orm.ValidateTable(typeof(Person), out errors, out warnings);
// validate multiple tables
bool success = orm.ValidateTables(new List<Type>
{
typeof(Person),
typeof(Order),
typeof(Inventory)
},
out errors,
out warnings);
if (errors.Count > 0)
foreach (string error in errors) Console.WriteLine(error);
if (warnings.Count > 0)
foreach (string warning in warnings) Console.WriteLine(warning);
Sqlite may not work out of the box with .NET Framework. In order to use Sqlite with .NET Framework, you'll need to manually copy the runtimes folder into your project output directory. This directory is automatically created when building for .NET Core. To get this folder, build the Test.Sqlite project and navigate to the bin/[debug||release]/[netcoreapp*||net5.0||net6.0] directory. Then copy the runtimes folder into the project output directory of your .NET Framework application.
In order to use pagination with SQL Server, the SelectMany method containing the ResultOrder[] resultOrder parameter must be used.
While the DateTimeOffset type can be used in objects, with MySQL the offset is not persisted. It is recommended that you store UTC timestamps using the DateTime type instead.
Use the MySQL constructor. MySQL constraints apply.
Refer to CHANGELOG.md.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 is compatible. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on WatsonORM.Sqlite:
| Package | Downloads |
|---|---|
|
WatsonORM
WatsonORM is a lightweight and easy to use object-relational mapper (ORM) in C# for .NET Core, .NET Framework, and .NET Standard built on top of DatabaseWrapper. WatsonORM supports Microsoft SQL Server, MySQL, PostgreSQL, and Sqlite databases. Refer to other WatsonORM packages if you only need support for a single database type. |
|
|
IndexEngine
Index engine is a simple indexer written in C# using Sqlite as a storage repository. |
|
|
WatsonDedupe
Standalone C# library for deduplication of data. |
|
|
GateKeeper
Lightweight library for implementing roles-based access control (RBAC). With Gatekeeper, you can define users, roles, resources, and permissions, and authorize requests. |
|
|
OpenAuditLog
Simple C# event library providing event persistence and allowing you to write your own emitters |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.14 | 9,230 | 2/4/2025 |
| 3.0.13 | 325 | 2/4/2025 |
| 3.0.12 | 323 | 2/4/2025 |
| 3.0.11 | 378 | 1/23/2025 |
| 3.0.10 | 307 | 1/23/2025 |
| 3.0.9 | 621 | 9/19/2024 |
| 3.0.8 | 3,700 | 10/4/2023 |
| 3.0.6 | 670 | 9/30/2023 |
| 3.0.5 | 435 | 9/30/2023 |
| 3.0.3 | 1,131 | 8/29/2023 |
| 3.0.0 | 3,111 | 7/11/2023 |
| 2.1.2 | 2,160 | 2/3/2023 |
| 2.1.0 | 3,282 | 10/25/2022 |
| 2.0.2.3 | 1,442 | 10/4/2022 |
| 2.0.1.2 | 2,291 | 9/22/2022 |
| 2.0.1.1 | 3,360 | 9/4/2022 |
| 2.0.1 | 3,241 | 6/21/2022 |
| 2.0.0.5 | 2,733 | 5/27/2022 |
| 2.0.0.1 | 4,452 | 1/3/2022 |
| 1.3.5.4 | 2,083 | 11/20/2021 |
Better support for updating multiple objects