internal override IList GetIListSourceListInternal()
 {
     if (this._cachedBindingList == null)
     {
         this.EnsureCanEnumerateResults();
         this._cachedBindingList = ObjectViewFactory.CreateViewForQuery <T>(this._resultItemType, (IEnumerable <T>) this, this._shaper.Context, this._shaper.MergeOption == MergeOption.NoTracking, this._singleEntitySet);
     }
     return((IList)this._cachedBindingList);
 }
示例#2
0
        internal override IList GetIListSourceListInternal()
        {
            // You can only enumerate the query results once, and the creation of an ObjectView consumes this enumeration.
            // However, there are situations where setting the DataSource of a control can result in multiple calls to this method.
            // In order to enable this scenario and allow direct binding to the ObjectResult instance,
            // the ObjectView is cached and returned on subsequent calls to this method.

            if (_cachedBindingList == null)
            {
                EnsureCanEnumerateResults();

                var forceReadOnly = _shaper.MergeOption == MergeOption.NoTracking;
                _cachedBindingList = ObjectViewFactory.CreateViewForQuery(
                    _resultItemType, this, _shaper.Context, forceReadOnly, _singleEntitySet);
            }

            return(_cachedBindingList);
        }
示例#3
0
        internal static IBindingList CreateViewForQuery <TElement>(
            TypeUsage elementEdmTypeUsage,
            IEnumerable <TElement> queryResults,
            ObjectContext objectContext,
            bool forceReadOnly,
            EntitySet singleEntitySet)
        {
            Type      type1           = (Type)null;
            TypeUsage ospaceTypeUsage = ObjectViewFactory.GetOSpaceTypeUsage(elementEdmTypeUsage, objectContext);

            if (ospaceTypeUsage == null)
            {
                type1 = typeof(TElement);
            }
            Type         clrType            = ObjectViewFactory.GetClrType <TElement>(ospaceTypeUsage.EdmType);
            object       objectStateManager = (object)objectContext.ObjectStateManager;
            IBindingList bindingList;

            if (clrType == typeof(TElement))
            {
                bindingList = (IBindingList) new ObjectView <TElement>((IObjectViewData <TElement>) new ObjectViewQueryResultData <TElement>((IEnumerable)queryResults, objectContext, forceReadOnly, singleEntitySet), objectStateManager);
            }
            else if (clrType == (Type)null)
            {
                bindingList = (IBindingList) new DataRecordObjectView((IObjectViewData <DbDataRecord>) new ObjectViewQueryResultData <DbDataRecord>((IEnumerable)queryResults, objectContext, true, (EntitySet)null), objectStateManager, (RowType)ospaceTypeUsage.EdmType, typeof(TElement));
            }
            else
            {
                if (!typeof(TElement).IsAssignableFrom(clrType))
                {
                    throw EntityUtil.ValueInvalidCast(clrType, typeof(TElement));
                }
                Type   type2    = ObjectViewFactory._genericObjectViewQueryResultDataType.MakeGenericType(clrType);
                object viewData = type2.GetDeclaredConstructor(typeof(IEnumerable), typeof(ObjectContext), typeof(bool), typeof(EntitySet)).Invoke(new object[4]
                {
                    (object)queryResults,
                    (object)objectContext,
                    (object)forceReadOnly,
                    (object)singleEntitySet
                });
                bindingList = ObjectViewFactory.CreateObjectView(clrType, type2, viewData, objectStateManager);
            }
            return(bindingList);
        }
示例#4
0
        internal static IBindingList CreateViewForEntityCollection <TElement>(
            EntityType entityType,
            EntityCollection <TElement> entityCollection)
            where TElement : class
        {
            TypeUsage ospaceTypeUsage = ObjectViewFactory.GetOSpaceTypeUsage(entityType == null ? (TypeUsage)null : TypeUsage.Create((EdmType)entityType), entityCollection.ObjectContext);
            Type      type1;

            if (ospaceTypeUsage == null)
            {
                type1 = typeof(TElement);
            }
            else
            {
                type1 = ObjectViewFactory.GetClrType <TElement>(ospaceTypeUsage.EdmType);
                if (type1 == (Type)null)
                {
                    type1 = typeof(TElement);
                }
            }
            IBindingList bindingList;

            if (type1 == typeof(TElement))
            {
                bindingList = (IBindingList) new ObjectView <TElement>((IObjectViewData <TElement>) new ObjectViewEntityCollectionData <TElement, TElement>(entityCollection), (object)entityCollection);
            }
            else
            {
                if (!typeof(TElement).IsAssignableFrom(type1))
                {
                    throw EntityUtil.ValueInvalidCast(type1, typeof(TElement));
                }
                Type   type2    = ObjectViewFactory._genericObjectViewEntityCollectionDataType.MakeGenericType(type1, typeof(TElement));
                object viewData = type2.GetDeclaredConstructor(typeof(EntityCollection <TElement>)).Invoke(new object[1]
                {
                    (object)entityCollection
                });
                bindingList = ObjectViewFactory.CreateObjectView(type1, type2, viewData, (object)entityCollection);
            }
            return(bindingList);
        }