Click or drag to resize
ConnectionDeletePersistentObject Method
Deletes a persistent object from the data store.

Namespace: Obujekutoru
Assembly: obujekutoru (in obujekutoru.dll) Version: 1.0.0.19089 (1.0.0.*)
Syntax
public void DeletePersistentObject(
	PersistentObject persistentObject
)

Parameters

persistentObject
Type: ObujekutoruPersistentObject
The persistent object to be deleted.
Exceptions
ExceptionCondition
ArgumentNullExceptionPersistent object is null.
InvalidOperationException The connection has been disposed of, the persistent object is new, the persistent object is dirty, or the persistent object is already deleted.
Examples
using System;
using System.Collections;
using System.Collections.Generic;

using Obujekutoru;

namespace ObujekutoruExamples.ConnectionDeleteExample
{
    class Program
    {
        static void Main(string[] args)
        {
            String dataFolderPath = @"C:\Temp\ObujekutoruData";
            EncryptionType encryptionType = EncryptionType.DESEncryption;
            String encryptionKey = "A proavo habui, quod publicos litterarum ludos non frequentavi, et domi bonis praeceptoribus usus...";

            List<PersistentObject> persistentObjects;

            using (Connection connection = new Connection(dataFolderPath, encryptionType, encryptionKey, true))
            {
                PersistentObjectE persistentObjectE1 = new PersistentObjectE("persistent object E1");
                PersistentObjectE persistentObjectE2 = new PersistentObjectE("persistent object E2");
                PersistentObjectE persistentObjectE3 = new PersistentObjectE("persistent object E3");

                connection.InsertPersistentObject(persistentObjectE1);
                connection.InsertPersistentObject(persistentObjectE2);
                connection.InsertPersistentObject(persistentObjectE3);

                persistentObjects = connection.SelectPersistentObject(
                    typeof(PersistentObjectE),
                    PersistentObjectFieldFilterCollection.Empty().And(
                        "persistentObjectName", 
                        PersistentObjectFieldFilterOperator.Equal, 
                        "persistent object E2"),
                    PersistentObjectFieldSorterCollection.Empty(),
                    1, Int32.MaxValue);

                PersistentObjectE persistentObjectToDelete = (PersistentObjectE)persistentObjects[0];

                connection.DeletePersistentObject(persistentObjectToDelete);

                persistentObjects = connection.SelectPersistentObject(
                    typeof(PersistentObjectE),
                    PersistentObjectFieldFilterCollection.Empty(),
                    PersistentObjectFieldSorterCollection.Empty().And(
                        "persistentObjectName", PersistentObjectFieldSortOperator.Ascending),
                    1, Int32.MaxValue);

                Console.WriteLine("persistentObjects[0] = {0}", (persistentObjects[0] as PersistentObjectE).PersistentObjectName);
                Console.WriteLine("persistentObjects[1] = {0}", (persistentObjects[1] as PersistentObjectE).PersistentObjectName);
            }
        }
    }

    [PersistentObject("PersistentObjectE")]
    internal class PersistentObjectE : PersistentObject
    {
        [PersistentObjectField("persistentObjectName", true)]
        private String _persistentObjectName;

        public PersistentObjectE()
        { }
        public PersistentObjectE(String persistentObjectName)
        {
            _persistentObjectName = persistentObjectName;
        }

        public String PersistentObjectName
        {
            get { return _persistentObjectName; }
            set
            {
                _persistentObjectName = value;
                _isDirty = true;
                _updated = DateTime.UtcNow;
            }
        }
    }
}
See Also