Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,43 +41,44 @@ 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](http://help.dataobjects.net).

// 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();
```csharp
// 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";
}
}

// on application shutdown dispose existing domain
domain.Dispose()
// 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()
```


### Getting support
Expand Down Expand Up @@ -110,4 +111,4 @@ Version.props file declares version is building. `<DoVersion>` tag defiles versi

### License

DataObjects.Net and its extensions published here are licensed under the [MIT](https://github.com/DataObjects-NET/dataobjects-net/blob/master/License.txt) license.
DataObjects.Net and its extensions published here are licensed under the [MIT](https://github.com/DataObjects-NET/dataobjects-net/blob/master/License.txt) license.