an Example of creating copies of the data object

Full list of code examples Flexberry ORM is in “code Examples”.

Example of creating copies of the data object

Console.WriteLine("7. Prototyping.");
IDataService dataService = DataServiceProvider.DataService;
OrmSample ormSample = new OrmSample(dataService);
object primaryKey = ormSample.GetSomeObjectPrimaryKey(typeof(D0));

D0 aggregator = new D0();
aggregator.SetExistObjectPrimaryKey(primaryKey);

Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();

dataService.LoadObject(D0.Views.D0_E, aggregator);

stopwatch.Stop();
long loadObjectTime = stopwatch.ElapsedMilliseconds;
stopwatch.Restart();

// This method makes each object in the hierarchy of new (see listing below). 
aggregator.Prototype(true);

stopwatch.Stop();
long prototypingTime = stopwatch.ElapsedMilliseconds;
stopwatch.Restart();

dataService.UpdateObject(aggregator);

stopwatch.Stop();
long updateTime = stopwatch.ElapsedMilliseconds;

Console.WriteLine("Time taken for loading: {1} ms{0}prototyping: {2} ms{0}persistence: {3} ms.", Environment.NewLine, loadObjectTime, prototypingTime, updateTime);

Method code Prototype:

public virtual void Prototype(bool withDetails)
{
    KeyGenerator.Generate(this, null);
    this.SetStatus(ObjectStatus.Created);
    this.SetLoadingState(LoadingState.NotLoaded);
    this.SetLoadedProperties(new string[0]);
    InitDataCopy();
    if (withDetails)
    {
        string[] properties = Information.GetAllPropertyNames(GetType());
        foreach (string property in properties)
        {
            Type proptype = Information.GetPropertyType(GetType(), property);
            if (proptype.IsSubclassOf(typeof(DetailArray)))
            {
                foreach (D detobj in (DetailArray)Information.GetPropValueByName(this, property))
                    detobj.Prototype(withDetails);
            }
        }
    }
}