Overview
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.
Adding DataObjects.Net to project
1.Open NuGet Package Manager and search for Xtensive.Orm
2.Install Xtensive.Orm package
The package will automatically install all dependencies.
3.Install desired data providers
Install the desired provider from the list of DataObjects.Net packages. For now we support MS SQL Server, Oracle, PostgreSQL, MySQL, Firebird and SQLite.
4.Install DataObjects.Net extensions (optional)
Extensions are small projects that extend standard functionality of DataObjects.Net core. For now there are 5 extensions: Bulk operations, Localization, Reprocessing, Security & ASP.NET Core integration.
DataObjects.Net in action
1. Define domain model
First of all, you define domain model containing one or more persistent entities. Application development with DataObjects.Net follows the domain-driven design principle, so the model can be declared directly and completely in source code using attributes.
[HierarchyRoot] public class Message : Entity { [Field, Key] public int Id { get; private set; } [Field(Length = 100)] public string Text { get; set; } }
2. Build domain
Next step is to configure and build a domain for the model defined above. Domain can be configured to work with different data sources, such as in-memory database (IMDB) or SQL Servers.
// Creating a new domain configuration var configuration = new DomainConfiguration("sqlserver://localhost/MyDatabase") { UpgradeMode = DomainUpgradeMode.Recreate }; // Registering persistent entities configuration.Types.Register(typeof(Message).Assembly); // Building domain var domain = Domain.Build(configuration);
3. Work with entities
After the domain is built, we open a session and transaction to work with persistent entities. DataObjects.Net transparently populates their property values from the database, as well as flushes the changes made to persistent entities back. The persistence layer also does performance acceleration like lazy loading and caching behind the scenes.
using (var session = domain.OpenSession()) { using (var transactionScope = session.OpenTransaction()) { // Creating new Message var message = new Message() { Text = "Hello World!" }; // This query will be translated to ~ SELECT ... WHERE message.Text LIKE "Hello%" var helloMessages = from message in session.Query.All<Message>() where message.Text.StartsWith("Hello") select message; foreach (var message in helloMessages) Console.WriteLine(message.Text); transactionScope.Complete(); } }
Feel the power
DataObjects.Net dramatically simplifies the development and maintenance of modern data-centric applications. It allows you to focus on code of business tier and application data model, it completely solves a set of programming and architectural tasks that could take up to 40% of overall development time.
See our Manual for detailed story.