DataObjects.Net is a persistence and object-relational mapping framework for the Microsoft .NET. It allows developers to define persistent objects as well as business logic directly in C#, Visual Basic or F#. The persistent objects can be retrieved by LINQ queries. Persistent data can be stored in SQL Servers. In contrast to many other ORM frameworks the database model is generated and maintained automatically.
Supported databases:
- MS SQL Server 2008 R2, 2012, 2014, 2016, 2017, 2019
- MS Azure SQL Database
- Oracle 10g, 11g
- PostgreSQL 8.3, 8.4, 9.0, 9.1, 9.2, 10, 11
- MySQL 5.5, 5.6
- Firebird 2.5
- Sqlite 3
DataObjects.Net is available on Nuget. Install main package (already has MS SQL Server provider included)
dotnet add package Xtensive.Orm
Providers for Oracle, PostgreSQL, Mysql, Firebird and SQLite may be installed optionally if you need them
dotnet add package Xtensive.Orm.Oracle
dotnet add package Xtensive.Orm.PostgreSQL
dotnet add package Xtensive.Orm.MySql
dotnet add package Xtensive.Orm.Firebird
dotnet add package Xtensive.Orm
DataObjects.Net extensions are available on Nuget as well (more about extensions here)
dotnet add package Xtensive.Orm.BulkOperations
dotnet add package Xtensive.Orm.Localization
dotnet add package Xtensive.Orm.Logging.log4net
dotnet add package Xtensive.Orm.Reprocessing
dotnet add package Xtensive.Orm.Security
dotnet add package Xtensive.Orm.Tracking
dotnet add package Xtensive.Orm.Web
Use the --version option to specify preview version to install
The following code demonstrates basic usage of DataObjects.Net. For full tutorial configuring Domain, defining the model and querying data see our documentation.
// create configuration with connection to Tests database on local instance of MS SQL Server
var domainConfiguration = new DomainConfiguration(@"sqlserver://localhost/Tests");
// register types from certain domain
domainConfiguration.Types.Register(typeof (Person).Assembly, typeof (Person).Namespace);
// create database structure from scratch
domainConfiguration.UpgradeMode = DomainUpgradeMode.Recreate;
// on application start build Domain
var domain = Domain.Build(domainConfiguration);
// open a session to database
using (var session = domain.OpenSession()) {
using (var transactionScope = session.OpenTransaction()) {
// query for existing Anton Chekhov
Author existingAuthor = session.Query.All<Author>()
.Where(author => author.FirstName=="Anton" && author.LastName=="Chekhov")
.FirstOrDefault();
//if Anton Pavlovich isn't in database yet then and him
if (existingAuthor==null) {
existingAuthor = new new Author(session) {
FirstName = "Anton",
LastName = "Chekhov";
}
}
// add new book and assign it with Anton Chekhov
existingAuthor.Books.Add(new Book(session) {Title = "The Cherry Orchard"});
// commit opened transaction to save changes made within it
transactionScope.Complete();
}
}
// on application shutdown dispose existing domain
domain.Dispose()
If you have a specific question about using DataObjects.Net you can ask on our support forum or send your question to support@dataobjects.net.
Repository contains two solutions - Orm
and Weaver
.
The Orm
solution contains DataObjects.Net projects and the extensions we develop and maintain (including tests).
The Weaver
solution contains projects which are responsible for post-build processing of assemblies containing inheritors of Xtensive.Orm.Persistent
class.
Simpliest way to build binaries of both solutions is to run
dotnet build Build.proj
It builds binaries and pack them to Nuget packages. Results of build are available in _Build
directory.
If packages aren't needed consider running
dotnet build Build.proj /t:BuildBinaries
Version.props file declares version is building. <DoVersion>
tag defiles version in <Major version>.<Minor version>.<Revision>
format. Do not define Build number, it is defined while building. <DoVersionSuffix>
should be defined for pre-release versions like Alphas, Betas, and RCs.
DataObjects.Net and its extensions published here are licensed under the MIT license.