Ejemplo n.º 1
0
        /// <summary>
        ///     Creates a new instance of an entity for the type of this set or for a type derived
        ///     from the type of this set.
        ///     Note that this instance is NOT added or attached to the set.
        ///     The instance returned will be a proxy if the underlying context is configured to create
        ///     proxies and the entity type meets the requirements for creating a proxy.
        /// </summary>
        /// <param name="derivedEntityType"> The type of entity to create. </param>
        /// <returns> The entity instance, which may be a proxy. </returns>
        public TEntity Create(Type derivedEntityType)
        {
            DebugCheck.NotNull(derivedEntityType);

            if (!typeof(TEntity).IsAssignableFrom(derivedEntityType))
            {
                throw Error.DbSet_BadTypeForCreate(derivedEntityType.Name, typeof(TEntity).Name);
            }

            return((TEntity)InternalContext.CreateObject(ObjectContextTypeCache.GetObjectType(derivedEntityType)));
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Creates a new instance of an entity for the type of this set.
 ///     Note that this instance is NOT added or attached to the set.
 ///     The instance returned will be a proxy if the underlying context is configured to create
 ///     proxies and the entity type meets the requirements for creating a proxy.
 /// </summary>
 /// <returns> The entity instance, which may be a proxy. </returns>
 public TEntity Create()
 {
     return(InternalContext.CreateObject <TEntity>());
 }