示例#1
0
 /// <summary>
 /// Gets an object that represents the collection navigation property from this
 /// entity to a collection of related entities.
 /// </summary>
 /// <typeparam name="TElement"> The type of elements in the collection. </typeparam>
 /// <param name="navigationProperty"> The name of the navigation property. </param>
 /// <returns> An object representing the navigation property. </returns>
 public DbCollectionEntry <TEntity, TElement> Collection <TElement>(
     string navigationProperty)
     where TElement : class
 {
     Check.NotEmpty(navigationProperty, nameof(navigationProperty));
     return(DbCollectionEntry <TEntity, TElement> .Create(this._internalEntityEntry.Collection(navigationProperty, typeof(TElement))));
 }
            public void Generic_DbCollectionEntry_typed_as_DbMemberEntry_can_be_implicitly_converted_to_non_generic_DbCollectionEntry()
            {
                DbMemberEntry <FakeWithProps, ICollection <FakeEntity> > propEntry =
                    new DbCollectionEntry <FakeWithProps, FakeEntity>(
                        new InternalCollectionEntry(
                            new Mock <InternalEntityEntryForMock <FakeEntity> >().Object, FakeWithProps.CollectionMetadata));

                NonGenericTestMethod((DbCollectionEntry)propEntry, "Collection");
            }
            public void Generic_DbCollectionEntry_can_be_implicitly_converted_to_non_generic_version()
            {
                var propEntry =
                    new DbCollectionEntry <FakeWithProps, FakeEntity>(
                        new InternalCollectionEntry(
                            new Mock <InternalEntityEntryForMock <FakeEntity> >().Object, FakeWithProps.CollectionMetadata));

                NonGenericTestMethod(propEntry, "Collection");
            }
示例#4
0
        /// <summary>
        /// Returns the equivalent generic <see cref="T:System.Data.Entity.Infrastructure.DbCollectionEntry`2" /> object.
        /// </summary>
        /// <typeparam name="TEntity"> The type of entity on which the member is declared. </typeparam>
        /// <typeparam name="TElement"> The type of the collection element. </typeparam>
        /// <returns> The equivalent generic object. </returns>
        public DbCollectionEntry <TEntity, TElement> Cast <TEntity, TElement>() where TEntity : class
        {
            MemberEntryMetadata entryMetadata = this._internalCollectionEntry.EntryMetadata;

            if (!typeof(TEntity).IsAssignableFrom(entryMetadata.DeclaringType) || !typeof(TElement).IsAssignableFrom(entryMetadata.ElementType))
            {
                throw Error.DbMember_BadTypeForCast((object)typeof(DbCollectionEntry).Name, (object)typeof(TEntity).Name, (object)typeof(TElement).Name, (object)entryMetadata.DeclaringType.Name, (object)entryMetadata.ElementType.Name);
            }
            return(DbCollectionEntry <TEntity, TElement> .Create(this._internalCollectionEntry));
        }
示例#5
0
        /// <summary>
        /// Returns the equivalent generic <see cref="DbCollectionEntry{TEntity,TElement}" /> object.
        /// </summary>
        /// <typeparam name="TEntity"> The type of entity on which the member is declared. </typeparam>
        /// <typeparam name="TElement"> The type of the collection element. </typeparam>
        /// <returns> The equivalent generic object. </returns>
        public new DbCollectionEntry <TEntity, TElement> Cast <TEntity, TElement>() where TEntity : class
        {
            var metadata = _internalCollectionEntry.EntryMetadata;

            if (!typeof(TEntity).IsAssignableFrom(metadata.DeclaringType) ||
                !typeof(TElement).IsAssignableFrom(metadata.ElementType))
            {
                throw Error.DbMember_BadTypeForCast(
                          typeof(DbCollectionEntry).Name,
                          typeof(TEntity).Name,
                          typeof(TElement).Name,
                          metadata.DeclaringType.Name,
                          metadata.ElementType.Name);
            }

            return(DbCollectionEntry <TEntity, TElement> .Create(_internalCollectionEntry));
        }
 private static DbCollectionEntry ImplicitConvert(DbCollectionEntry nonGeneric)
 {
     return(nonGeneric);
 }
 private void NonGenericTestMethod(DbCollectionEntry nonGenericEntry, string name)
 {
     Assert.Same(name, nonGenericEntry.Name);
 }
        /// <summary>
        ///     Gets an object that represents the collection navigation property from this
        ///     entity to a collection of related entities.
        /// </summary>
        /// <param name="navigationProperty"> The name of the navigation property. </param>
        /// <returns> An object representing the navigation property. </returns>
        public DbCollectionEntry Collection(string navigationProperty)
        {
            Check.NotEmpty(navigationProperty, "navigationProperty");

            return(DbCollectionEntry.Create(_internalEntityEntry.Collection(navigationProperty)));
        }
示例#9
0
 /// <summary>
 /// Gets an object that represents the collection navigation property from this
 /// entity to a collection of related entities.
 /// </summary>
 /// <param name="navigationProperty"> The name of the navigation property. </param>
 /// <returns> An object representing the navigation property. </returns>
 public DbCollectionEntry Collection(string navigationProperty)
 {
     Check.NotEmpty(navigationProperty, nameof(navigationProperty));
     return(DbCollectionEntry.Create(this._internalEntityEntry.Collection(navigationProperty, (Type)null)));
 }