AspnetPaths Partial Class

This is the base partial data object class for the “paths” 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 AspnetPaths class.
///

public partial class AspnetPaths : IPersistable
{
#region Members

private bool isNew;
private bool _isNew;
private Guid applicationid;
private Guid pathid;
private string path;
private string loweredpath;

#endregion

#region Properties

///

/// The Applicationid.
///

public virtual Guid Applicationid
{
get { return this.applicationid; }
set { this.applicationid = value; }
}

///

/// The Pathid.
///

public virtual Guid Pathid
{
get { return this.pathid; }
set { this.pathid = value; }
}

///

/// The Path.
///

[StringInfo(256, true)]
public virtual string Path
{
get { return this.path; }
set { this.path = value; }
}

///

/// The Loweredpath.
///

[StringInfo(256, true)]
public virtual string Loweredpath
{
get { return this.loweredpath; }
set { this.loweredpath = value; }
}

#endregion

#region ColumnNames

///

/// The corresponding schema name.
///

internal const string SchemaName = “dbo”;

///

/// The corresponding table name.
///

internal const string TableName = “aspnet_Paths”;

///

/// The column names.
///

internal class ColumnNames
{
///

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

public const string Applicationid=”ApplicationId”;
///

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

public const string Pathid=”PathId”;
///

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

public const string Path=”Path”;
///

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

public const string Loweredpath=”LoweredPath”;
}

#endregion

///

/// The default constructor.
///

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

///

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

/// The Applicationid. /// The Pathid. /// The Path. /// The Loweredpath. public AspnetPaths(Guid applicationid, Guid pathid, string path, string loweredpath)
{
this.applicationid = applicationid;
this.pathid = pathid;
this.path = path;
this.loweredpath = loweredpath;

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

///

/// The constructor from IDataReader.
///

/// An initalized IDataReader. internal AspnetPaths(IDataReader reader)
{
if ((reader[“ApplicationId”] != null) && (reader[“ApplicationId”] != DBNull.Value))
this.applicationid = (Guid)reader[“ApplicationId”];
if ((reader[“PathId”] != null) && (reader[“PathId”] != DBNull.Value))
this.pathid = (Guid)reader[“PathId”];
if ((reader[“Path”] != null) && (reader[“Path”] != DBNull.Value))
this.path = (string)reader[“Path”];
if ((reader[“LoweredPath”] != null) && (reader[“LoweredPath”] != DBNull.Value))
this.loweredpath = (string)reader[“LoweredPath”];

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_Paths] ([ApplicationId], [PathId], [Path], [LoweredPath]) values (@applicationid, @pathid, @path, @loweredpath)”;
cmd.Parameters.AddWithValue(“@applicationid”, this.applicationid);
cmd.Parameters.AddWithValue(“@pathid”, this.pathid);
cmd.Parameters.AddWithValue(“@path”, this.path);
cmd.Parameters.AddWithValue(“@loweredpath”, this.loweredpath);

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_Paths] set [ApplicationId]=@applicationid, [Path]=@path, [LoweredPath]=@loweredpath where ([PathId]=@pathid)”;
cmd.Parameters.AddWithValue(“@applicationid”, this.applicationid);
cmd.Parameters.AddWithValue(“@path”, this.path);
cmd.Parameters.AddWithValue(“@loweredpath”, this.loweredpath);
cmd.Parameters.AddWithValue(“@pathid”, this.pathid);

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_Paths] where ([PathId]=@pathid)”;
cmd.Parameters.AddWithValue(“@pathid”, this.pathid);

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 AspnetPaths object by its primary key (Throws System.DataException).
///

/// The Pathid. /// The AspnetPaths object.
public static AspnetPaths Get(Guid pathid)
{
AspnetPaths aspnetpaths;
if (AspnetPaths.TryGet(pathid, out aspnetpaths))
return aspnetpaths;
else
throw new DataException(“‘AspnetPaths’ object not found.”);
}

///

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

/// The Pathid. /// The found AspnetPaths or null if the primary key value does not exist. /// True if the AspnetPaths exists, else false.
public static bool TryGet(Guid pathid, out AspnetPaths aspnetpaths)
{
SqlCommand cmd = new SqlCommand(“select * from [dbo].[aspnet_Paths] where ([PathId]=@pathid)”);
cmd.Parameters.AddWithValue(“@pathid”, pathid);

IList list = AspnetPaths.Query(cmd);

if (list.Count == 0)
{
aspnetpaths = null;
return false;
}
else
{
aspnetpaths = 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()
{
AspnetPaths aspnetpaths;

if (AspnetPaths.TryGet(this.pathid, out aspnetpaths))
{
this.isNew = false;
}
else
{
this.isNew = true;
}
}

///

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

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

dto.Applicationid = this.Applicationid;
dto.Pathid = this.Pathid;
dto.Path = this.Path;
dto.Loweredpath = this.Loweredpath;

return dto;
}

///

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

/// The Data Transfer Object. public virtual void SetDTO(AspnetPathsDTO dto)
{
this.Applicationid = dto.Applicationid;
this.Pathid = dto.Pathid;
this.Path = dto.Path;
this.Loweredpath = dto.Loweredpath;
}

///

/// Perfoms a query on AspnetPaths objects.
///

/// An IDbCommand containing the select statement. /// A result list of AspnetPaths 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 AspnetPaths(reader));
}

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

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

///

/// Finds all AspnetPaths objects with a certain Applicationid value.
///

/// The Applicationid value. /// All AspnetPaths objects with a certain Applicationid value.
public static IList FindByApplicationid(Guid applicationid)
{
return AspnetPaths.Query(AspnetPathsCommands.FindByApplicationid(applicationid));
}

///

/// Finds all AspnetPaths objects with a certain Path value.
///

/// The Path value (‘*’ can be used as a wildcard). /// All AspnetPaths objects with a certain Path value.
public static IList FindByPath(string path)
{
return AspnetPaths.Query(AspnetPathsCommands.FindByPath(path));
}

///

/// Finds all AspnetPaths objects with a certain Loweredpath value.
///

/// The Loweredpath value (‘*’ can be used as a wildcard). /// All AspnetPaths objects with a certain Loweredpath value.
public static IList FindByLoweredpath(string loweredpath)
{
return AspnetPaths.Query(AspnetPathsCommands.FindByLoweredpath(loweredpath));
}

}
}

[/csharp]

Share

Leave a Reply

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