// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.Infrastructure
{
using System.Data.Entity.Internal;
using System.Data.Entity.Resources;
using System.Data.Entity.Utilities;
///
/// A non-generic version of the class.
///
public class DbPropertyEntry : DbMemberEntry
{
#region Fields and constructors
private readonly InternalPropertyEntry _internalPropertyEntry;
///
/// Creates a from information in the given .
/// Use this method in preference to the constructor since it may potentially create a subclass depending on
/// the type of member represented by the InternalCollectionEntry instance.
///
/// The internal property entry.
/// The new entry.
internal static DbPropertyEntry Create(InternalPropertyEntry internalPropertyEntry)
{
DebugCheck.NotNull(internalPropertyEntry);
return (DbPropertyEntry)internalPropertyEntry.CreateDbMemberEntry();
}
///
/// Initializes a new instance of the class.
///
/// The internal entry.
internal DbPropertyEntry(InternalPropertyEntry internalPropertyEntry)
{
DebugCheck.NotNull(internalPropertyEntry);
_internalPropertyEntry = internalPropertyEntry;
}
#endregion
#region Name
///
/// Gets the property name.
///
/// The property name.
public override string Name
{
get { return _internalPropertyEntry.Name; }
}
#endregion
#region Current and Original values
///
/// Gets or sets the original value of this property.
///
/// The original value.
public object OriginalValue
{
get { return _internalPropertyEntry.OriginalValue; }
set { _internalPropertyEntry.OriginalValue = value; }
}
///
/// Gets or sets the current value of this property.
///
/// The current value.
public override object CurrentValue
{
get { return _internalPropertyEntry.CurrentValue; }
set { _internalPropertyEntry.CurrentValue = value; }
}
///
/// Gets or sets a value indicating whether the value of this property has been modified since
/// it was loaded from the database.
///
///
/// Setting this value to false for a modified property will revert the change by setting the
/// current value to the original value. If the result is that no properties of the entity are
/// marked as modified, then the entity will be marked as Unchanged.
/// Setting this value to false for properties of Added, Unchanged, or Deleted entities
/// is a no-op.
///
///
/// true if this instance is modified; otherwise, false .
///
public bool IsModified
{
get { return _internalPropertyEntry.IsModified; }
set { _internalPropertyEntry.IsModified = value; }
}
#endregion
#region Back references
///
/// The to which this property belongs.
///
/// An entry for the entity that owns this property.
public override DbEntityEntry EntityEntry
{
get { return new DbEntityEntry(_internalPropertyEntry.InternalEntityEntry); }
}
///
/// The of the property for which this is a nested property.
/// This method will only return a non-null entry for properties of complex objects; it will
/// return null for properties of the entity itself.
///
/// An entry for the parent complex property, or null if this is an entity property.
public DbComplexPropertyEntry ParentProperty
{
get
{
var propertyEntry = _internalPropertyEntry.ParentPropertyEntry;
return propertyEntry != null ? DbComplexPropertyEntry.Create(propertyEntry) : null;
}
}
#endregion
#region InternalMemberEntry access
///
/// Gets the backing this object.
///
/// The internal member entry.
internal override InternalMemberEntry InternalMemberEntry
{
get { return _internalPropertyEntry; }
}
#endregion
#region Conversion to generic
///
/// Returns the equivalent generic object.
///
/// The type of entity on which the member is declared.
/// The type of the property.
/// The equivalent generic object.
public new DbPropertyEntry Cast() where TEntity : class
{
var metadata = _internalPropertyEntry.EntryMetadata;
if (!typeof(TEntity).IsAssignableFrom(metadata.DeclaringType)
|| !typeof(TProperty).IsAssignableFrom(metadata.ElementType))
{
throw Error.DbMember_BadTypeForCast(
typeof(DbPropertyEntry).Name,
typeof(TEntity).Name,
typeof(TProperty).Name,
metadata.DeclaringType.Name,
metadata.MemberType.Name);
}
return DbPropertyEntry.Create(_internalPropertyEntry);
}
#endregion
}
}