AspnetPersonalizationperuser Partial Class

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

public partial class AspnetPersonalizationperuser : IPersistable
{
#region Members

private bool isNew;
private bool _isNew;
private Guid id;
private Nullable pathid;
private Nullable userid;
private byte[] pagesettings;
private DateTime lastupdateddate;

#endregion

#region Properties

///

/// The Id.
///

public virtual Guid Id
{
get { return this.id; }
set { this.id = value; }
}

///

/// The Pathid.
///

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

///

/// The Userid.
///

public virtual Nullable Userid
{
get { return this.userid; }
set { this.userid = value; }
}

///

/// The Pagesettings.
///

public virtual byte[] Pagesettings
{
get { return this.pagesettings; }
set { this.pagesettings = value; }
}

///

/// The Lastupdateddate.
///

public virtual DateTime Lastupdateddate
{
get { return this.lastupdateddate; }
set { this.lastupdateddate = value; }
}

#endregion

#region ColumnNames

///

/// The corresponding schema name.
///

internal const string SchemaName = “dbo”;

///

/// The corresponding table name.
///

internal const string TableName = “aspnet_PersonalizationPerUser”;

///

/// The column names.
///

internal class ColumnNames
{
///

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

public const string Id=”Id”;
///

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

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

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

public const string Userid=”UserId”;
///

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

public const string Pagesettings=”PageSettings”;
///

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

public const string Lastupdateddate=”LastUpdatedDate”;
}

#endregion

///

/// The default constructor.
///

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

///

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

/// The Id. /// The Pagesettings. /// The Lastupdateddate. public AspnetPersonalizationperuser(Guid id, byte[] pagesettings, DateTime lastupdateddate)
{
this.id = id;
this.pagesettings = pagesettings;
this.lastupdateddate = lastupdateddate;

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

///

/// The constructor from IDataReader.
///

/// An initalized IDataReader. internal AspnetPersonalizationperuser(IDataReader reader)
{
if ((reader[“Id”] != null) && (reader[“Id”] != DBNull.Value))
this.id = (Guid)reader[“Id”];
if ((reader[“PathId”] != null) && (reader[“PathId”] != DBNull.Value))
this.pathid = (Nullable)reader[“PathId”];
if ((reader[“UserId”] != null) && (reader[“UserId”] != DBNull.Value))
this.userid = (Nullable)reader[“UserId”];
if ((reader[“PageSettings”] != null) && (reader[“PageSettings”] != DBNull.Value))
this.pagesettings = (byte[])reader[“PageSettings”];
if ((reader[“LastUpdatedDate”] != null) && (reader[“LastUpdatedDate”] != DBNull.Value))
this.lastupdateddate = (DateTime)reader[“LastUpdatedDate”];

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_PersonalizationPerUser] ([Id], [PathId], [UserId], [PageSettings], [LastUpdatedDate]) values (@id, @pathid, @userid, @pagesettings, @lastupdateddate)”;
cmd.Parameters.AddWithValue(“@id”, this.id);
if (!this.pathid.HasValue)
cmd.Parameters.AddWithValue(“@pathid”, DBNull.Value);
else
cmd.Parameters.AddWithValue(“@pathid”, this.pathid.Value);
if (!this.userid.HasValue)
cmd.Parameters.AddWithValue(“@userid”, DBNull.Value);
else
cmd.Parameters.AddWithValue(“@userid”, this.userid.Value);
cmd.Parameters.AddWithValue(“@pagesettings”, this.pagesettings);
cmd.Parameters.AddWithValue(“@lastupdateddate”, this.lastupdateddate);

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_PersonalizationPerUser] set [PathId]=@pathid, [UserId]=@userid, [PageSettings]=@pagesettings, [LastUpdatedDate]=@lastupdateddate where ([Id]=@id)”;
if (!this.pathid.HasValue)
cmd.Parameters.AddWithValue(“@pathid”, DBNull.Value);
else
cmd.Parameters.AddWithValue(“@pathid”, this.pathid.Value);
if (!this.userid.HasValue)
cmd.Parameters.AddWithValue(“@userid”, DBNull.Value);
else
cmd.Parameters.AddWithValue(“@userid”, this.userid.Value);
cmd.Parameters.AddWithValue(“@pagesettings”, this.pagesettings);
cmd.Parameters.AddWithValue(“@lastupdateddate”, this.lastupdateddate);
cmd.Parameters.AddWithValue(“@id”, this.id);

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

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

/// The Id. /// The AspnetPersonalizationperuser object.
public static AspnetPersonalizationperuser Get(Guid id)
{
AspnetPersonalizationperuser aspnetpersonalizationperuser;
if (AspnetPersonalizationperuser.TryGet(id, out aspnetpersonalizationperuser))
return aspnetpersonalizationperuser;
else
throw new DataException(“‘AspnetPersonalizationperuser’ object not found.”);
}

///

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

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

IList list = AspnetPersonalizationperuser.Query(cmd);

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

if (AspnetPersonalizationperuser.TryGet(this.id, out aspnetpersonalizationperuser))
{
this.isNew = false;
}
else
{
this.isNew = true;
}
}

///

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

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

dto.Id = this.Id;
dto.Pathid = this.Pathid;
dto.Userid = this.Userid;
dto.Pagesettings = this.Pagesettings;
dto.Lastupdateddate = this.Lastupdateddate;

return dto;
}

///

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

/// The Data Transfer Object. public virtual void SetDTO(AspnetPersonalizationperuserDTO dto)
{
this.Id = dto.Id;
this.Pathid = dto.Pathid;
this.Userid = dto.Userid;
this.Pagesettings = dto.Pagesettings;
this.Lastupdateddate = dto.Lastupdateddate;
}

///

/// Perfoms a query on AspnetPersonalizationperuser objects.
///

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

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

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

///

/// Finds all AspnetPersonalizationperuser objects with a certain Pathid value.
///

/// The Pathid value. /// All AspnetPersonalizationperuser objects with a certain Pathid value.
public static IList FindByPathid(Nullable pathid)
{
return AspnetPersonalizationperuser.Query(AspnetPersonalizationperuserCommands.FindByPathid(pathid));
}

///

/// Finds all AspnetPersonalizationperuser objects with a certain Userid value.
///

/// The Userid value. /// All AspnetPersonalizationperuser objects with a certain Userid value.
public static IList FindByUserid(Nullable userid)
{
return AspnetPersonalizationperuser.Query(AspnetPersonalizationperuserCommands.FindByUserid(userid));
}

///

/// Finds all AspnetPersonalizationperuser objects with a certain Pagesettings value.
///

/// The Pagesettings value. /// All AspnetPersonalizationperuser objects with a certain Pagesettings value.
public static IList FindByPagesettings(byte[] pagesettings)
{
return AspnetPersonalizationperuser.Query(AspnetPersonalizationperuserCommands.FindByPagesettings(pagesettings));
}

///

/// Finds all AspnetPersonalizationperuser objects with a certain Lastupdateddate value.
///

/// The Lastupdateddate value. /// All AspnetPersonalizationperuser objects with a certain Lastupdateddate value.
public static IList FindByLastupdateddate(DateTime lastupdateddate)
{
return AspnetPersonalizationperuser.Query(AspnetPersonalizationperuserCommands.FindByLastupdateddate(lastupdateddate));
}

}
}

[/csharp]

Share

Leave a Reply

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