Click here to Skip to main content
15,896,453 members
Articles / Hosted Services / Azure

DataObjects.Net - ORM Framework for RAD - Introduction

Rate me:
Please Sign up or sign in to vote.
4.85/5 (15 votes)
7 Sep 2010CPOL11 min read 50.1K   1.1K   32  
Introduction into the ORM Framework DataObjects.Net from x-tensive
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Samples-EntityCreation.cs" company="">
//   
// </copyright>
// <summary>
//   The program.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DO4_Introduction
{
    using System;
    using System.Diagnostics;

    using DO4_Introduction.Model;

    using Xtensive.Storage;

    /// <summary>
    /// The program.
    /// </summary>
    public partial class Program
    {
        #region Methods

        /// <summary>
        /// The create derived entities.
        /// </summary>
        /// <param name="domain">
        /// The domain.
        /// </param>
        /// <param name="provider">
        /// The provider.
        /// </param>
        private static void CreateDerivedEntities(Domain domain, string provider)
        {
            Console.WriteLine(provider + ": Creating DerivedEntity objects start");
            var stopwatch = new Stopwatch();
            using (Session.Open(domain))
            {
                using (TransactionScope transactionScope = Transaction.Open())
                {
                    new DerivedEntity { DerivedEntityData = "Warmup" };
                    new DerivedEntity { DerivedEntityData = "Warmup" };

                    stopwatch.Start();
                    for (int i = 0; i < 10000; ++i)
                    {
                        new DerivedEntity { DerivedEntityData = "Derived Entity Number: " + i };
                    }

                    transactionScope.Complete();
                    stopwatch.Stop();
                }

                Console.WriteLine(provider + ": Creating DerivedEntity objects finish in " + stopwatch.ElapsedMilliseconds + " mS");
            }
        }

        /// <summary>
        /// The create indexed data entities.
        /// </summary>
        /// <param name="domain">
        /// The domain.
        /// </param>
        /// <param name="provider">
        /// The provider.
        /// </param>
        private static void CreateIndexedDataEntities(Domain domain, string provider)
        {
            Console.WriteLine(provider + ": Creating IndexedDataEntity objects start");
            var stopwatch = new Stopwatch();
            using (Session.Open(domain))
            {
                int dataValue = 0;
                using (TransactionScope transactionScope = Transaction.Open())
                {
                    new IndexedDataEntity { Data = dataValue++ };
                    new IndexedDataEntity { Data = dataValue++ };

                    stopwatch.Start();
                    for (int i = 0; i < 10000; ++i)
                    {
                        new IndexedDataEntity { Data = dataValue++ };
                    }

                    transactionScope.Complete();
                    stopwatch.Stop();
                }

                Console.WriteLine(provider + ": Creating IndexedDataEntity objects finish in " + stopwatch.ElapsedMilliseconds + " mS");
            }
        }

        /// <summary>
        /// The create parent child entities.
        /// </summary>
        /// <param name="domain">
        /// The domain.
        /// </param>
        /// <param name="provider">
        /// The provider.
        /// </param>
        private static void CreateParentChildEntities(Domain domain, string provider)
        {
            Console.WriteLine(provider + ": Creating ParentEntity -> ChildEntity objects start");
            var stopwatch = new Stopwatch();
            using (Session.Open(domain))
            {
                using (TransactionScope transactionScope = Transaction.Open())
                {
                    var parentWarmup = new ParentEntity();
                    new ChildEntity(parentWarmup);
                    new ChildEntity(parentWarmup);
                    new ChildEntity(parentWarmup);

                    stopwatch.Start();
                    for (int i = 0; i < 100; ++i)
                    {
                        var parent = new ParentEntity();
                        for (int j = 0; j < 100; ++j)
                        {
                            new ChildEntity(parent);
                        }
                    }

                    transactionScope.Complete();
                    stopwatch.Stop();
                }

                Console.WriteLine(provider + ": Creating ParentEntity -> ChildEntity objects finish in " + stopwatch.ElapsedMilliseconds + " mS");
            }
        }

        /// <summary>
        /// The create simple entities multiple transactions.
        /// </summary>
        /// <param name="domain">
        /// The domain.
        /// </param>
        /// <param name="provider">
        /// The provider.
        /// </param>
        private static void CreateSimpleEntitiesMultipleTransactions(Domain domain, string provider)
        {
            Console.WriteLine(provider + ": Creating SimpleEntity objects start");
            var stopwatch = new Stopwatch();
            using (Session.Open(domain))
            {
                using (TransactionScope transactionScope = Transaction.Open())
                {
                    new SimpleEntity { Data = "Warmup" };
                    new SimpleEntity { Data = "Warmup" };
                    transactionScope.Complete();
                }

                stopwatch.Start();
                for (int i = 0; i < 10000; ++i)
                {
                    using (TransactionScope transactionScope = Transaction.Open())
                    {
                        new SimpleEntity { Data = "Multiple Transactions Entity Number: " + i };
                        transactionScope.Complete();
                    }
                }

                stopwatch.Stop();

                Console.WriteLine(provider + ": Creating SimpleEntity objects finish in " + stopwatch.ElapsedMilliseconds + " mS");
            }
        }

        /// <summary>
        /// The create simple entities single tansaction.
        /// </summary>
        /// <param name="domain">
        /// The domain.
        /// </param>
        /// <param name="provider">
        /// The provider.
        /// </param>
        private static void CreateSimpleEntitiesSingleTansaction(Domain domain, string provider)
        {
            Console.WriteLine(provider + ": Creating SimpleEntity objects start");
            var stopwatch = new Stopwatch();
            using (Session.Open(domain))
            {
                using (TransactionScope transactionScope = Transaction.Open())
                {
                    new SimpleEntity { Data = "Warmup" };
                    new SimpleEntity { Data = "Warmup" };

                    stopwatch.Start();
                    for (int i = 0; i < 10000; ++ i)
                    {
                        new SimpleEntity { Data = "Single Transaction Entity Number: " + i };
                    }

                    transactionScope.Complete();
                    stopwatch.Stop();
                }

                Console.WriteLine(provider + ": Creating SimpleEntity objects finish in " + stopwatch.ElapsedMilliseconds + " mS");
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO
Germany Germany
I'm a Senior Software Consultant
Thomas Maierhofer Consulting

Comments and Discussions