// 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; using System.Diagnostics.CodeAnalysis; /// /// A non-generic version of the class. /// public class DbComplexPropertyEntry : DbPropertyEntry { #region Fields and constructors /// /// 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 new static DbComplexPropertyEntry Create(InternalPropertyEntry internalPropertyEntry) { DebugCheck.NotNull(internalPropertyEntry); return (DbComplexPropertyEntry)internalPropertyEntry.CreateDbMemberEntry(); } /// /// Initializes a new instance of the class. /// /// The internal entry. internal DbComplexPropertyEntry(InternalPropertyEntry internalPropertyEntry) : base(internalPropertyEntry) { } #endregion #region Access to nested properties /// /// Gets an object that represents a nested property of this property. /// This method can be used for both scalar or complex properties. /// /// The name of the nested property. /// An object representing the nested property. public DbPropertyEntry Property(string propertyName) { Check.NotEmpty(propertyName, "propertyName"); return DbPropertyEntry.Create(((InternalPropertyEntry)InternalMemberEntry).Property(propertyName)); } /// /// Gets an object that represents a nested complex property of this property. /// /// The name of the nested property. /// An object representing the nested property. [SuppressMessage("Microsoft.Naming", "CA1719:ParameterNamesShouldNotMatchMemberNames", MessageId = "0#", Justification = "Rule predates more fluent naming conventions.")] public DbComplexPropertyEntry ComplexProperty(string propertyName) { Check.NotEmpty(propertyName, "propertyName"); return Create(((InternalPropertyEntry)InternalMemberEntry).Property(propertyName, null, requireComplex: true)); } #endregion #region Conversion to generic /// /// Returns the equivalent generic object. /// /// The type of entity on which the member is declared. /// The type of the complex property. /// The equivalent generic object. public new DbComplexPropertyEntry Cast() where TEntity : class { var metadata = InternalMemberEntry.EntryMetadata; if (!typeof(TEntity).IsAssignableFrom(metadata.DeclaringType) || !typeof(TComplexProperty).IsAssignableFrom(metadata.ElementType)) { throw Error.DbMember_BadTypeForCast( typeof(DbComplexPropertyEntry).Name, typeof(TEntity).Name, typeof(TComplexProperty).Name, metadata.DeclaringType.Name, metadata.MemberType.Name); } return DbComplexPropertyEntry.Create((InternalPropertyEntry)InternalMemberEntry); } #endregion } }