コード例 #1
0
        /// <summary>
        /// Delete an existing instance from database.
        /// </summary>
        /// <param name="instance">Instance unique identifier.</param>
        private static int DeleteDatabaseRecord(long id)
        {
            ORMSqlCommand cmd = ORMEntity <T> .SqlDialect.GetDeleteCommand();

            // Delete foreign records
            ORMEntity <T> .DeleteDatabaseForeignRecords(id);

            // Connecto to database
            ORMEntity <T> .Connect();

            // Set command parameters
            ORMEntity <T> .SetParameter(cmd.PrimaryKeyName, id);

            // Execute the SQL command
            int rowsAffected = ExecuteNonQuery(cmd.SqlCommand);

            // Close the connection to database
            ORMEntity <T> .Disconnect();

            // Delete the instance from in-memory database
            if (ORMEntity <T> .InMemoryTable.ContainsKey(id))
            {
                ORMEntity <T> .InMemoryTable.Remove(id);
            }

            return(rowsAffected);
        }