Ejemplo n.º 1
0
        public override IEnumerable <T> GetNestedLinkSource <T>(int iGlobalLink, int iLocalFactory, object instance)
        {
            IDeferredSourceFactory factory = (IDeferredSourceFactory)this.Locals[iLocalFactory];

            if (factory == null)
            {
                MetaDataMember member = (MetaDataMember)this.Globals[iGlobalLink];
                factory = this.services.GetDeferredSourceFactory(member);
                this.Locals[iLocalFactory] = factory;
            }
            return((IEnumerable <T>)factory.CreateDeferredSource(instance));
        }
Ejemplo n.º 2
0
                private void InitializeDeferredLoader(MetaDataMember deferredMember)
                {
                    MetaAccessor acc = deferredMember.StorageAccessor;

                    if (!acc.HasAssignedValue(this.current) && !acc.HasLoadedValue(this.current))
                    {
                        MetaAccessor dsacc  = deferredMember.DeferredSourceAccessor;
                        IEnumerable  loader = (IEnumerable)dsacc.GetBoxedValue(this.current);
                        // don't reset loader on any deferred member that already has one
                        if (loader == null)
                        {
                            IDeferredSourceFactory factory = this.tracker.services.GetDeferredSourceFactory(deferredMember);
                            loader = factory.CreateDeferredSource(this.current);
                            dsacc.SetBoxedValue(ref this.current, loader);
                        }
                        else if (loader != null && !haveInitializedDeferredLoaders)
                        {
                            // If loader is present but wasn't generated by us, then
                            // an attempt to Attach or Add an entity from another context
                            // has been made, which is not supported.
                            throw Error.CannotAttachAddNonNewEntities();
                        }
                    }
                }