AspnetProfile Partial Class
This is the base partial data object class for the “profile” 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.
- //*****************************************************************************
- // 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
- {
- /// <summary>
- /// The AspnetProfile class.
- /// </summary>
- public partial class AspnetProfile : IPersistable
- {
- #region Members
- private bool isNew;
- private bool _isNew;
- private Guid userid;
- private string propertynames;
- private string propertyvaluesstring;
- private byte[] propertyvaluesbinary;
- private DateTime lastupdateddate;
- #endregion
- #region Properties
- /// <summary>
- /// The Userid.
- /// </summary>
- public virtual Guid Userid
- {
- get { return this.userid; }
- set { this.userid = value; }
- }
- /// <summary>
- /// The Propertynames.
- /// </summary>
- public virtual string Propertynames
- {
- get { return this.propertynames; }
- set { this.propertynames = value; }
- }
- /// <summary>
- /// The Propertyvaluesstring.
- /// </summary>
- public virtual string Propertyvaluesstring
- {
- get { return this.propertyvaluesstring; }
- set { this.propertyvaluesstring = value; }
- }
- /// <summary>
- /// The Propertyvaluesbinary.
- /// </summary>
- public virtual byte[] Propertyvaluesbinary
- {
- get { return this.propertyvaluesbinary; }
- set { this.propertyvaluesbinary = value; }
- }
- /// <summary>
- /// The Lastupdateddate.
- /// </summary>
- public virtual DateTime Lastupdateddate
- {
- get { return this.lastupdateddate; }
- set { this.lastupdateddate = value; }
- }
- #endregion
- #region ColumnNames
- /// <summary>
- /// The corresponding schema name.
- /// </summary>
- internal const string SchemaName = "dbo";
- /// <summary>
- /// The corresponding table name.
- /// </summary>
- internal const string TableName = "aspnet_Profile";
- /// <summary>
- /// The column names.
- /// </summary>
- internal class ColumnNames
- {
- /// <summary>
- /// The column name of the Userid property.
- /// </summary>
- public const string Userid="UserId";
- /// <summary>
- /// The column name of the Propertynames property.
- /// </summary>
- public const string Propertynames="PropertyNames";
- /// <summary>
- /// The column name of the Propertyvaluesstring property.
- /// </summary>
- public const string Propertyvaluesstring="PropertyValuesString";
- /// <summary>
- /// The column name of the Propertyvaluesbinary property.
- /// </summary>
- public const string Propertyvaluesbinary="PropertyValuesBinary";
- /// <summary>
- /// The column name of the Lastupdateddate property.
- /// </summary>
- public const string Lastupdateddate="LastUpdatedDate";
- }
- #endregion
- /// <summary>
- /// The default constructor.
- /// </summary>
- public AspnetProfile()
- {
- this.isNew = true;
- PersistenceManager.InvokeInstanceMethod(this, "CreationComplete", null);
- }
- /// <summary>
- /// The constructor of the required fields.
- /// </summary>
- /// <param name="userid">The Userid.</param>
- /// <param name="propertynames">The Propertynames.</param>
- /// <param name="propertyvaluesstring">The Propertyvaluesstring.</param>
- /// <param name="propertyvaluesbinary">The Propertyvaluesbinary.</param>
- /// <param name="lastupdateddate">The Lastupdateddate.</param>
- public AspnetProfile(Guid userid, string propertynames, string propertyvaluesstring, byte[] propertyvaluesbinary, DateTime lastupdateddate)
- {
- this.userid = userid;
- this.propertynames = propertynames;
- this.propertyvaluesstring = propertyvaluesstring;
- this.propertyvaluesbinary = propertyvaluesbinary;
- this.lastupdateddate = lastupdateddate;
- this.isNew = true;
- PersistenceManager.InvokeInstanceMethod(this, "CreationComplete", null);
- }
- /// <summary>
- /// The constructor from IDataReader.
- /// </summary>
- /// <param name="reader">An initalized IDataReader.</param>
- internal AspnetProfile(IDataReader reader)
- {
- if ((reader["UserId"] != null) && (reader["UserId"] != DBNull.Value))
- this.userid = (Guid)reader["UserId"];
- if ((reader["PropertyNames"] != null) && (reader["PropertyNames"] != DBNull.Value))
- this.propertynames = (string)reader["PropertyNames"];
- if ((reader["PropertyValuesString"] != null) && (reader["PropertyValuesString"] != DBNull.Value))
- this.propertyvaluesstring = (string)reader["PropertyValuesString"];
- if ((reader["PropertyValuesBinary"] != null) && (reader["PropertyValuesBinary"] != DBNull.Value))
- this.propertyvaluesbinary = (byte[])reader["PropertyValuesBinary"];
- if ((reader["LastUpdatedDate"] != null) && (reader["LastUpdatedDate"] != DBNull.Value))
- this.lastupdateddate = (DateTime)reader["LastUpdatedDate"];
- this.isNew = false;
- }
- /// <summary>
- /// Creates an IDbCommand to insert an object into the database.
- /// </summary>
- /// <returns>An initialized IDbCommand object.</returns>
- internal virtual IDbCommand CreateInsertCommand()
- {
- SqlCommand cmd = new SqlCommand();
- cmd.CommandText = "insert into [dbo].[aspnet_Profile] ([UserId], [PropertyNames], [PropertyValuesString], [PropertyValuesBinary], [LastUpdatedDate]) values (@userid, @propertynames, @propertyvaluesstring, @propertyvaluesbinary, @lastupdateddate)";
- cmd.Parameters.AddWithValue("@userid", this.userid);
- cmd.Parameters.AddWithValue("@propertynames", this.propertynames);
- cmd.Parameters.AddWithValue("@propertyvaluesstring", this.propertyvaluesstring);
- cmd.Parameters.AddWithValue("@propertyvaluesbinary", this.propertyvaluesbinary);
- cmd.Parameters.AddWithValue("@lastupdateddate", this.lastupdateddate);
- cmd.Connection = PersistenceManager.Connection;
- return cmd;
- }
- /// <summary>
- /// Creates an IDbCommand to update an object in the database.
- /// </summary>
- /// <returns>An initialized IDbCommand object.</returns>
- internal virtual IDbCommand CreateUpdateCommand()
- {
- SqlCommand cmd = new SqlCommand();
- cmd.CommandText = "update [dbo].[aspnet_Profile] set [PropertyNames]=@propertynames, [PropertyValuesString]=@propertyvaluesstring, [PropertyValuesBinary]=@propertyvaluesbinary, [LastUpdatedDate]=@lastupdateddate where ([UserId]=@userid)";
- cmd.Parameters.AddWithValue("@propertynames", this.propertynames);
- cmd.Parameters.AddWithValue("@propertyvaluesstring", this.propertyvaluesstring);
- cmd.Parameters.AddWithValue("@propertyvaluesbinary", this.propertyvaluesbinary);
- cmd.Parameters.AddWithValue("@lastupdateddate", this.lastupdateddate);
- cmd.Parameters.AddWithValue("@userid", this.userid);
- cmd.Connection = PersistenceManager.Connection;
- return cmd;
- }
- /// <summary>
- /// Creates an IDbCommand to delete an object in the database.
- /// </summary>
- /// <returns>An initialized IDbCommand object.</returns>
- internal virtual IDbCommand CreateDeleteCommand()
- {
- SqlCommand cmd = new SqlCommand();
- cmd.CommandText = "delete from [dbo].[aspnet_Profile] where ([UserId]=@userid)";
- cmd.Parameters.AddWithValue("@userid", this.userid);
- cmd.Connection = PersistenceManager.Connection;
- return cmd;
- }
- /// <summary>
- /// Persists the object.
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// Deletes the object.
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// Retrieves a AspnetProfile object by its primary key (Throws System.DataException).
- /// </summary>
- /// <param name="userid">The Userid.</param>
- /// <returns>The AspnetProfile object.</returns>
- public static AspnetProfile Get(Guid userid)
- {
- AspnetProfile aspnetprofile;
- if (AspnetProfile.TryGet(userid, out aspnetprofile))
- return aspnetprofile;
- else
- throw new DataException("'AspnetProfile' object not found.");
- }
- /// <summary>
- /// Tries to retrieve a AspnetProfile object by its primary key.
- /// </summary>
- /// <param name="userid">The Userid.</param>
- /// <param name="aspnetprofile">The found AspnetProfile or null if the primary key value does not exist.</param>
- /// <returns>True if the AspnetProfile exists, else false.</returns>
- public static bool TryGet(Guid userid, out AspnetProfile aspnetprofile)
- {
- SqlCommand cmd = new SqlCommand("select * from [dbo].[aspnet_Profile] where ([UserId]=@userid)");
- cmd.Parameters.AddWithValue("@userid", userid);
- IList<AspnetProfile> list = AspnetProfile.Query(cmd);
- if (list.Count == 0)
- {
- aspnetprofile = null;
- return false;
- }
- else
- {
- aspnetprofile = list[0];
- return true;
- }
- }
- /// <summary>
- /// For internal use only.
- /// </summary>
- public virtual void SaveState()
- {
- this._isNew = this.isNew;
- }
- /// <summary>
- /// For internal use only.
- /// </summary>
- public virtual void RestoreState()
- {
- this.isNew = this._isNew;
- }
- /// <summary>
- /// Refreshes the internal state of the object.
- /// </summary>
- /// <remarks>This method should be called after xml deserialization to refresh internal flags.</remarks>
- public virtual void RefreshState()
- {
- AspnetProfile aspnetprofile;
- if (AspnetProfile.TryGet(this.userid, out aspnetprofile))
- {
- this.isNew = false;
- }
- else
- {
- this.isNew = true;
- }
- }
- /// <summary>
- /// Returns a Data Transfer Object of this AspnetProfile.
- /// </summary>
- /// <returns>A Data Transfer Object of this AspnetProfile.</returns>
- public virtual AspnetProfileDTO GetDTO()
- {
- AspnetProfileDTO dto = new AspnetProfileDTO();
- dto.Userid = this.Userid;
- dto.Propertynames = this.Propertynames;
- dto.Propertyvaluesstring = this.Propertyvaluesstring;
- dto.Propertyvaluesbinary = this.Propertyvaluesbinary;
- dto.Lastupdateddate = this.Lastupdateddate;
- return dto;
- }
- /// <summary>
- /// Applies a Data Transfer Object data to this AspnetProfile.
- /// </summary>
- /// <param name="dto">The Data Transfer Object.</param>
- public virtual void SetDTO(AspnetProfileDTO dto)
- {
- this.Userid = dto.Userid;
- this.Propertynames = dto.Propertynames;
- this.Propertyvaluesstring = dto.Propertyvaluesstring;
- this.Propertyvaluesbinary = dto.Propertyvaluesbinary;
- this.Lastupdateddate = dto.Lastupdateddate;
- }
- /// <summary>
- /// Perfoms a query on AspnetProfile objects.
- /// </summary>
- /// <param name="command">An IDbCommand containing the select statement.</param>
- /// <returns>A result list of AspnetProfile objects.</returns>
- internal static IList<AspnetProfile> 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<AspnetProfile> list = new List<AspnetProfile>();
- IDataReader reader = command.ExecuteReader();
- using (reader)
- {
- while (reader.Read())
- list.Add(new AspnetProfile(reader));
- }
- if (connWasClosed)
- PersistenceManager.Connection.Close();
- return list;
- }
- catch (Exception ex)
- {
- if (connWasClosed)
- PersistenceManager.Connection.Close();
- throw ex;
- }
- }
- /// <summary>
- /// Finds all AspnetProfile objects with a certain Propertynames value.
- /// </summary>
- /// <param name="propertynames">The Propertynames value ('*' can be used as a wildcard).</param>
- /// <returns>All AspnetProfile objects with a certain Propertynames value.</returns>
- public static IList<AspnetProfile> FindByPropertynames(string propertynames)
- {
- return AspnetProfile.Query(AspnetProfileCommands.FindByPropertynames(propertynames));
- }
- /// <summary>
- /// Finds all AspnetProfile objects with a certain Propertyvaluesstring value.
- /// </summary>
- /// <param name="propertyvaluesstring">The Propertyvaluesstring value ('*' can be used as a wildcard).</param>
- /// <returns>All AspnetProfile objects with a certain Propertyvaluesstring value.</returns>
- public static IList<AspnetProfile> FindByPropertyvaluesstring(string propertyvaluesstring)
- {
- return AspnetProfile.Query(AspnetProfileCommands.FindByPropertyvaluesstring(propertyvaluesstring));
- }
- /// <summary>
- /// Finds all AspnetProfile objects with a certain Propertyvaluesbinary value.
- /// </summary>
- /// <param name="propertyvaluesbinary">The Propertyvaluesbinary value.</param>
- /// <returns>All AspnetProfile objects with a certain Propertyvaluesbinary value.</returns>
- public static IList<AspnetProfile> FindByPropertyvaluesbinary(byte[] propertyvaluesbinary)
- {
- return AspnetProfile.Query(AspnetProfileCommands.FindByPropertyvaluesbinary(propertyvaluesbinary));
- }
- /// <summary>
- /// Finds all AspnetProfile objects with a certain Lastupdateddate value.
- /// </summary>
- /// <param name="lastupdateddate">The Lastupdateddate value.</param>
- /// <returns>All AspnetProfile objects with a certain Lastupdateddate value.</returns>
- public static IList<AspnetProfile> FindByLastupdateddate(DateTime lastupdateddate)
- {
- return AspnetProfile.Query(AspnetProfileCommands.FindByLastupdateddate(lastupdateddate));
- }
- }
- }
Articles & Research
SharePoint Security
SharePoint Development
SharePoint Architecture
Claims Authentication
Forefront For SharePoint
AIS / Dynamics GP
Team Foundation Server
Pex And Moles
ISA/TMG/IAG/UAG
DPM
Cardspace
Research Methodology
Rural ICT Development
Numerical Analysis
Multi-Level Research
Knowledge Management
Personal/Off-Topic