diff --git a/ReadMe.md b/ReadMe.md index b34d8c3c6f..02f189f7ed 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -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() - .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() + .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 @@ -110,4 +111,4 @@ Version.props file declares version is building. `` 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. \ No newline at end of file +DataObjects.Net and its extensions published here are licensed under the [MIT](https://github.com/DataObjects-NET/dataobjects-net/blob/master/License.txt) license.