日期:2014-05-20 浏览次数:20827 次
//===================================================================================
// Microsoft Developer & Platform Evangelism
//===================================================================================
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// This code is released under the terms of the MS-LPL license,
// http://microsoftnlayerapp.codeplex.com/license
//===================================================================================
namespace xx.xx.xx.xx
{
using System;
/// <summary>
/// Base class for entities
/// </summary>
public abstract partial class Entity
{
#region Members
int? _requestedHashCode;
Guid _Id;
#endregion
#region Properties
/// <summary>
/// Get the persisten object identifier
/// </summary>
public virtual Guid Id
{
get
{
return _Id;
}
protected set
{
_Id = value;
}
}
#endregion
#region Public Methods
/// <summary>
/// Check if this entity is transient, ie, without identity at this moment
/// </summary>
/// <returns>True if entity is transient, else false</returns>
public bool IsTransient()
{
return this.Id == Guid.Empty;
}
/// <summary>
/// Generate identity for this entity
/// </summary>
public void GenerateNewIdentity()
{
if ( IsTransient())
this.Id = IdentityGenerator.NewSequentialGuid();
}
/// <summary>
/// Change current identity for a new non transient identity
/// </summary>
/// <param name="identity">the new identity</param>
public void ChangeCurrentIdentity(Guid identity)
{
if ( identity != Guid.Empty)
this.Id = identity;
}
#endregion
#region Overrides Methods