WatsonORM 3.0.6
See the version list below for details.
dotnet add package WatsonORM --version 3.0.6
NuGet\Install-Package WatsonORM -Version 3.0.6
<PackageReference Include="WatsonORM" Version="3.0.6" />
paket add WatsonORM --version 3.0.6
#r "nuget: WatsonORM, 3.0.6"
// Install WatsonORM as a Cake Addin #addin nuget:?package=WatsonORM&version=3.0.6 // Install WatsonORM as a Cake Tool #tool nuget:?package=WatsonORM&version=3.0.6
WatsonORM
Library | Version | Downloads |
---|---|---|
WatsonORM (all supported database types) | ||
WatsonORM.Mysql | ||
WatsonORM.Postgresql | ||
WatsonORM.Sqlite | ||
WatsonORM.SqlServer | ||
WatsonORM.Core |
Description
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:
- Annotate classes and automatically create database tables
- Quickly create, read, update, or delete database records using your own objects
- Reduce time-to-production and time spent building scaffolding code
- Programmatic table creation and removal
For a sample app exercising this library, refer to the Test
project contained within the solution.
New in v3.0.x
- Dependency update
- Minor breaking changes
- Async API support
- Better support for updating multiple records
Special Thanks
We'd like to give special thanks to those who have contributed or helped make the library better!
@Maclay74 @flo2000ace @MacKey-255
Simple Example
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);
Column Naming
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; }
Pagination with SelectMany
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.
Validating One or More Tables
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);
Using Sqlite
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.
Using SQL Server
In order to use pagination with SQL Server, the SelectMany
method containing the ResultOrder[] resultOrder
parameter must be used.
Using MySQL
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.
Using MariaDB
Use the MySQL constructor. MySQL constraints apply.
Version history
Refer to CHANGELOG.md.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.1
- WatsonORM.Mysql (>= 3.0.6)
- WatsonORM.Postgresql (>= 3.0.6)
- WatsonORM.Sqlite (>= 3.0.6)
- WatsonORM.SqlServer (>= 3.0.6)
-
.NETFramework 4.8
- WatsonORM.Mysql (>= 3.0.6)
- WatsonORM.Postgresql (>= 3.0.6)
- WatsonORM.Sqlite (>= 3.0.6)
- WatsonORM.SqlServer (>= 3.0.6)
-
.NETStandard 2.1
- WatsonORM.Mysql (>= 3.0.6)
- WatsonORM.Postgresql (>= 3.0.6)
- WatsonORM.Sqlite (>= 3.0.6)
- WatsonORM.SqlServer (>= 3.0.6)
-
net6.0
- WatsonORM.Mysql (>= 3.0.6)
- WatsonORM.Postgresql (>= 3.0.6)
- WatsonORM.Sqlite (>= 3.0.6)
- WatsonORM.SqlServer (>= 3.0.6)
-
net7.0
- WatsonORM.Mysql (>= 3.0.6)
- WatsonORM.Postgresql (>= 3.0.6)
- WatsonORM.Sqlite (>= 3.0.6)
- WatsonORM.SqlServer (>= 3.0.6)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on WatsonORM:
Package | Downloads |
---|---|
Komodo.Classes
Do not install directly. Supporting classes for Komodo. Please either install Komodo.Daemon to integrate search within your application, or Komodo.Server to run a standalone server. Komodo is an information search, metadata, storage, and retrieval platform. |
|
Less3
<3 Less3 is S3-compatible object storage that you can run on your laptop, server, or anywhere you like. |
|
Komodo.Core
Komodo core libraries for crawling (file, object, web, database), parsing (JSON, XML, SQL, Sqlite, HTML, text), postings (inverted index, token extraction), indexing (search), metadata generation, and integrating within your application. Komodo is an information search, metadata, storage, and retrieval platform. |
|
NetLedger
NetLedger is a simple, self-contained ledgering library for adding debits and credits, checking balances, and performing commits on pending entries. NetLedger is self-contained and uses Sqlite; should you need a version using an external database, please contact us. |
|
Kvpbase.StorageServer
Scalable, simple RESTful object storage platform. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.0.9 | 176 | 9/19/2024 |
3.0.8 | 1,548 | 10/4/2023 |
3.0.7 | 174 | 10/3/2023 |
3.0.6 | 231 | 9/30/2023 |
3.0.3 | 244 | 8/29/2023 |
3.0.0 | 3,093 | 7/11/2023 |
2.1.2 | 1,633 | 2/3/2023 |
2.1.0 | 2,686 | 10/25/2022 |
2.0.2.3 | 760 | 10/4/2022 |
2.0.1.2 | 1,694 | 9/22/2022 |
2.0.1.1 | 1,866 | 9/4/2022 |
2.0.1 | 1,886 | 6/21/2022 |
2.0.0.5 | 546 | 5/27/2022 |
2.0.0.1 | 1,544 | 1/3/2022 |
1.3.5.4 | 1,503 | 11/20/2021 |
1.3.5.3 | 797 | 11/12/2021 |
1.3.5.1 | 2,040 | 10/14/2021 |
1.3.5 | 3,459 | 6/16/2021 |
1.3.4 | 432 | 6/16/2021 |
1.3.3 | 461 | 6/15/2021 |
1.3.2 | 2,062 | 4/15/2021 |
1.3.1 | 1,291 | 3/2/2021 |
1.3.0.23 | 1,426 | 2/9/2021 |
1.3.0.22 | 3,187 | 12/29/2020 |
1.3.0.21 | 2,595 | 11/28/2020 |
1.3.0.19 | 3,704 | 11/15/2020 |
1.3.0.17 | 631 | 11/10/2020 |
1.3.0.16 | 559 | 11/9/2020 |
1.3.0.15 | 9,414 | 10/19/2020 |
1.3.0.14 | 662 | 10/15/2020 |
1.3.0.13 | 683 | 10/6/2020 |
1.3.0.12 | 587 | 10/5/2020 |
1.3.0.11 | 633 | 9/19/2020 |
1.3.0.9 | 809 | 9/16/2020 |
1.3.0.8 | 690 | 9/16/2020 |
1.3.0.7 | 643 | 9/15/2020 |
1.3.0.6 | 621 | 9/10/2020 |
1.3.0.5 | 3,713 | 9/8/2020 |
1.3.0.4 | 670 | 9/8/2020 |
1.3.0.3 | 832 | 9/8/2020 |
1.3.0.2 | 3,691 | 8/17/2020 |
1.3.0.1 | 8,312 | 7/28/2020 |
1.3.0 | 13,581 | 7/10/2020 |
1.2.3.3 | 1,386 | 6/20/2020 |
1.2.3.2 | 638 | 6/20/2020 |
1.2.3.1 | 686 | 6/19/2020 |
1.2.3 | 1,005 | 6/15/2020 |
1.2.2 | 629 | 6/15/2020 |
1.2.1 | 621 | 6/15/2020 |
1.2.0.4 | 658 | 6/15/2020 |
1.2.0.3 | 608 | 6/15/2020 |
1.2.0 | 27,151 | 6/11/2020 |
1.1.3.1 | 770 | 6/10/2020 |
1.1.3 | 1,698 | 6/5/2020 |
1.1.2.1 | 722 | 6/4/2020 |
1.1.2 | 740 | 6/3/2020 |
1.1.1.1 | 1,525 | 5/28/2020 |
1.1.1 | 650 | 5/28/2020 |
1.1.0.9 | 1,563 | 5/22/2020 |
1.1.0.8 | 622 | 5/22/2020 |
1.1.0.7 | 676 | 5/22/2020 |
1.1.0.6 | 677 | 5/22/2020 |
1.1.0.5 | 664 | 5/22/2020 |
1.1.0.4 | 747 | 5/21/2020 |
1.0.0.4 | 1,068 | 5/19/2020 |
1.0.0.3 | 1,405 | 5/17/2020 |
1.0.0.2 | 617 | 5/13/2020 |
1.0.0.1 | 2,415 | 5/12/2020 |
1.0.0 | 888 | 5/12/2020 |
Better support for updating multiple objects