AspnetSchemaversions Partial Class

This is the base partial data object class for the “schemaversions” table in the provider database. Using this class implies that there will be a singular relationship between the remaining provider tables and relevant data objects.

[csharp]
//*****************************************************************************
// This file is part of the data access layer example to the ASP.NET 2.0 provider database
// This file was written by Adam Buenz [WSS MVP] of ARB Security Solutions, LLC
// http://www.sharepointsecurity.com
//
// This file and its parts is free for re-distribution, for use in both free
// and commercial applications, however this header must remain intact for legal
// use. The data access layer example is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//*****************************************************************************
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Aspnet.Provider.Datalayer.Commands;
using Aspnet.Provider.Datalayer.DataTransferObjects;

namespace Aspnet.Provider.Datalayer
{
///

/// The AspnetSchemaversions class.
///

public partial class AspnetSchemaversions : IPersistable
{
#region Members

private bool isNew;
private bool _isNew;
private string feature;
private string compatibleschemaversion;
private bool iscurrentversion;

#endregion

#region Properties

///

/// The Feature.
///

[StringInfo(128, true)]
public virtual string Feature
{
get { return this.feature; }
set { this.feature = value; }
}

///

/// The Compatibleschemaversion.
///

[StringInfo(128, true)]
public virtual string Compatibleschemaversion
{
get { return this.compatibleschemaversion; }
set { this.compatibleschemaversion = value; }
}

///

/// The Iscurrentversion.
///

public virtual bool Iscurrentversion
{
get { return this.iscurrentversion; }
set { this.iscurrentversion = value; }
}

#endregion

#region ColumnNames

///

/// The corresponding schema name.
///

internal const string SchemaName = “dbo”;

///

/// The corresponding table name.
///

internal const string TableName = “aspnet_SchemaVersions”;

///

/// The column names.
///

internal class ColumnNames
{
///

/// The column name of the Feature property.
///

public const string Feature=”Feature”;
///

/// The column name of the Compatibleschemaversion property.
///

public const string Compatibleschemaversion=”CompatibleSchemaVersion”;
///

/// The column name of the Iscurrentversion property.
///

public const string Iscurrentversion=”IsCurrentVersion”;
}

#endregion

///

/// The default constructor.
///

public AspnetSchemaversions()
{
this.isNew = true;
PersistenceManager.InvokeInstanceMethod(this, “CreationComplete”, null);
}

///

/// The constructor of the required fields.
///

/// The Feature. /// The Compatibleschemaversion. /// The Iscurrentversion. public AspnetSchemaversions(string feature, string compatibleschemaversion, bool iscurrentversion)
{
this.feature = feature;
this.compatibleschemaversion = compatibleschemaversion;
this.iscurrentversion = iscurrentversion;

this.isNew = true;
PersistenceManager.InvokeInstanceMethod(this, “CreationComplete”, null);
}

///

/// The constructor from IDataReader.
///

/// An initalized IDataReader. internal AspnetSchemaversions(IDataReader reader)
{
if ((reader[“Feature”] != null) && (reader[“Feature”] != DBNull.Value))
this.feature = (string)reader[“Feature”];
if ((reader[“CompatibleSchemaVersion”] != null) && (reader[“CompatibleSchemaVersion”] != DBNull.Value))
this.compatibleschemaversion = (string)reader[“CompatibleSchemaVersion”];
if ((reader[“IsCurrentVersion”] != null) && (reader[“IsCurrentVersion”] != DBNull.Value))
this.iscurrentversion = (bool)reader[“IsCurrentVersion”];

this.isNew = false;
}

///

/// Creates an IDbCommand to insert an object into the database.
///

/// An initialized IDbCommand object.
internal virtual IDbCommand CreateInsertCommand()
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = “insert into [dbo].[aspnet_SchemaVersions] ([Feature], [CompatibleSchemaVersion], [IsCurrentVersion]) values (@feature, @compatibleschemaversion, @iscurrentversion)”;
cmd.Parameters.AddWithValue(“@feature”, this.feature);
cmd.Parameters.AddWithValue(“@compatibleschemaversion”, this.compatibleschemaversion);
cmd.Parameters.AddWithValue(“@iscurrentversion”, this.iscurrentversion);

cmd.Connection = PersistenceManager.Connection;
return cmd;
}

///

/// Creates an IDbCommand to update an object in the database.
///

/// An initialized IDbCommand object.
internal virtual IDbCommand CreateUpdateCommand()
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = “update [dbo].[aspnet_SchemaVersions] set [IsCurrentVersion]=@iscurrentversion where ([Feature]=@feature) and ([CompatibleSchemaVersion]=@compatibleschemaversion)”;
cmd.Parameters.AddWithValue(“@iscurrentversion”, this.iscurrentversion);
cmd.Parameters.AddWithValue(“@feature”, this.feature);
cmd.Parameters.AddWithValue(“@compatibleschemaversion”, this.compatibleschemaversion);

cmd.Connection = PersistenceManager.Connection;
return cmd;
}

///

/// Creates an IDbCommand to delete an object in the database.
///

/// An initialized IDbCommand object.
internal virtual IDbCommand CreateDeleteCommand()
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = “delete from [dbo].[aspnet_SchemaVersions] where ([Feature]=@feature) and ([CompatibleSchemaVersion]=@compatibleschemaversion)”;
cmd.Parameters.AddWithValue(“@feature”, this.feature);
cmd.Parameters.AddWithValue(“@compatibleschemaversion”, this.compatibleschemaversion);

cmd.Connection = PersistenceManager.Connection;
return cmd;
}

///

/// Persists the object.
///

public virtual void Persist()
{
PersistenceManager.InvokeInstanceMethod(this, “PrePersist”, null);

IDbCommand cmd;

if (this.isNew)
cmd = this.CreateInsertCommand();
else
cmd = this.CreateUpdateCommand();

cmd.Transaction = PersistenceManager.Transaction;
PersistenceManager.RegisterInTransaction(this);

bool connWasClosed =
PersistenceManager.Connection.State.Equals(ConnectionState.Closed) ||
PersistenceManager.Connection.State.Equals(ConnectionState.Broken);

try
{
if (connWasClosed)
PersistenceManager.Connection.Open();

cmd.ExecuteNonQuery();

this.isNew = false;

if (connWasClosed)
PersistenceManager.Connection.Close();
}
catch (Exception ex)
{
if (connWasClosed)
PersistenceManager.Connection.Close();
throw ex;
}
}

///

/// Deletes the object.
///

public virtual void Delete()
{
PersistenceManager.InvokeInstanceMethod(this, “PreDelete”, null);

IDbCommand cmd = this.CreateDeleteCommand();
cmd.Transaction = PersistenceManager.Transaction;

bool connWasClosed =
PersistenceManager.Connection.State.Equals(ConnectionState.Closed) ||
PersistenceManager.Connection.State.Equals(ConnectionState.Broken);

try
{
if (connWasClosed)
PersistenceManager.Connection.Open();

cmd.ExecuteNonQuery();

if (connWasClosed)
PersistenceManager.Connection.Close();
}
catch (Exception ex)
{
if (connWasClosed)
PersistenceManager.Connection.Close();
throw ex;
}
}

///

/// Retrieves a AspnetSchemaversions object by its primary key (Throws System.DataException).
///

/// The Feature. /// The Compatibleschemaversion. /// The AspnetSchemaversions object.
public static AspnetSchemaversions Get(string feature, string compatibleschemaversion)
{
AspnetSchemaversions aspnetschemaversions;
if (AspnetSchemaversions.TryGet(feature, compatibleschemaversion, out aspnetschemaversions))
return aspnetschemaversions;
else
throw new DataException(“‘AspnetSchemaversions’ object not found.”);
}

///

/// Tries to retrieve a AspnetSchemaversions object by its primary key.
///

/// The Feature. /// The Compatibleschemaversion. /// The found AspnetSchemaversions or null if the primary key value does not exist. /// True if the AspnetSchemaversions exists, else false.
public static bool TryGet(string feature, string compatibleschemaversion, out AspnetSchemaversions aspnetschemaversions)
{
SqlCommand cmd = new SqlCommand(“select * from [dbo].[aspnet_SchemaVersions] where ([Feature]=@feature) and ([CompatibleSchemaVersion]=@compatibleschemaversion)”);
cmd.Parameters.AddWithValue(“@feature”, feature);
cmd.Parameters.AddWithValue(“@compatibleschemaversion”, compatibleschemaversion);

IList list = AspnetSchemaversions.Query(cmd);

if (list.Count == 0)
{
aspnetschemaversions = null;
return false;
}
else
{
aspnetschemaversions = list[0];
return true;
}
}

///

/// For internal use only.
///

public virtual void SaveState()
{
this._isNew = this.isNew;
}

///

/// For internal use only.
///

public virtual void RestoreState()
{
this.isNew = this._isNew;
}

///

/// Refreshes the internal state of the object.
///

/// This method should be called after xml deserialization to refresh internal flags.
public virtual void RefreshState()
{
AspnetSchemaversions aspnetschemaversions;

if (AspnetSchemaversions.TryGet(this.feature, this.compatibleschemaversion, out aspnetschemaversions))
{
this.isNew = false;
}
else
{
this.isNew = true;
}
}

///

/// Returns a Data Transfer Object of this AspnetSchemaversions.
///

/// A Data Transfer Object of this AspnetSchemaversions.
public virtual AspnetSchemaversionsDTO GetDTO()
{
AspnetSchemaversionsDTO dto = new AspnetSchemaversionsDTO();

dto.Feature = this.Feature;
dto.Compatibleschemaversion = this.Compatibleschemaversion;
dto.Iscurrentversion = this.Iscurrentversion;

return dto;
}

///

/// Applies a Data Transfer Object data to this AspnetSchemaversions.
///

/// The Data Transfer Object. public virtual void SetDTO(AspnetSchemaversionsDTO dto)
{
this.Feature = dto.Feature;
this.Compatibleschemaversion = dto.Compatibleschemaversion;
this.Iscurrentversion = dto.Iscurrentversion;
}

///

/// Perfoms a query on AspnetSchemaversions objects.
///

/// An IDbCommand containing the select statement. /// A result list of AspnetSchemaversions objects.
internal static IList Query(IDbCommand command)
{
command.Connection = PersistenceManager.Connection;
command.Transaction = PersistenceManager.Transaction;

bool connWasClosed =
PersistenceManager.Connection.State.Equals(ConnectionState.Closed) ||
PersistenceManager.Connection.State.Equals(ConnectionState.Broken);

try
{
if (connWasClosed)
PersistenceManager.Connection.Open();

List list = new List();
IDataReader reader = command.ExecuteReader();

using (reader)
{
while (reader.Read())
list.Add(new AspnetSchemaversions(reader));
}

if (connWasClosed)
PersistenceManager.Connection.Close();

return list;
}
catch (Exception ex)
{
if (connWasClosed)
PersistenceManager.Connection.Close();
throw ex;
}
}

///

/// Finds all AspnetSchemaversions objects with a certain Feature value.
///

/// The Feature value (‘*’ can be used as a wildcard). /// All AspnetSchemaversions objects with a certain Feature value.
public static IList FindByFeature(string feature)
{
return AspnetSchemaversions.Query(AspnetSchemaversionsCommands.FindByFeature(feature));
}

///

/// Finds all AspnetSchemaversions objects with a certain Compatibleschemaversion value.
///

/// The Compatibleschemaversion value (‘*’ can be used as a wildcard). /// All AspnetSchemaversions objects with a certain Compatibleschemaversion value.
public static IList FindByCompatibleschemaversion(string compatibleschemaversion)
{
return AspnetSchemaversions.Query(AspnetSchemaversionsCommands.FindByCompatibleschemaversion(compatibleschemaversion));
}

///

/// Finds all AspnetSchemaversions objects with a certain Iscurrentversion value.
///

/// The Iscurrentversion value. /// All AspnetSchemaversions objects with a certain Iscurrentversion value.
public static IList FindByIscurrentversion(bool iscurrentversion)
{
return AspnetSchemaversions.Query(AspnetSchemaversionsCommands.FindByIscurrentversion(iscurrentversion));
}

}
}

[/csharp]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *