コード例 #1
0
        /// <summary>
        /// We only get here if a navigation property getter returns null.  In this case, we try to set the
        /// navigation property to some collection that will work.
        /// </summary>
        private static Func <object> CreateCollectionCreateDelegate(Type entityType, Type navigationPropertyType, string propName)
        {
            var typeToInstantiate = EntityUtil.DetermineCollectionType(navigationPropertyType);

            if (typeToInstantiate == null)
            {
                throw new EntityException(System.Data.Entity.Strings.PocoEntityWrapper_UnableToMaterializeArbitaryNavPropType(propName, navigationPropertyType));
            }

            return(Expression.Lambda <Func <object> >(Expression.New(typeToInstantiate)).Compile());
        }
        private static Func <object> CreateCollectionCreateDelegate(
            Type navigationPropertyType,
            string propName)
        {
            Type collectionType = EntityUtil.DetermineCollectionType(navigationPropertyType);

            if (collectionType == (Type)null)
            {
                throw new EntityException(Strings.PocoEntityWrapper_UnableToMaterializeArbitaryNavPropType((object)propName, (object)navigationPropertyType));
            }
            return(Expression.Lambda <Func <object> >((Expression)DelegateFactory.GetNewExpressionForCollectionType(collectionType), new ParameterExpression[0]).Compile());
        }