示例#1
0
 private void InitializeUnderlyingTypes(EntitySetTypePair pair)
 {
     this._entitySet           = pair.EntitySet;
     this._baseType            = pair.BaseType;
     this._entitySetName       = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}.{1}", (object)this._entitySet.EntityContainer.Name, (object)this._entitySet.Name);
     this._quotedEntitySetName = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}.{1}", (object)DbHelpers.QuoteIdentifier(this._entitySet.EntityContainer.Name), (object)DbHelpers.QuoteIdentifier(this._entitySet.Name));
     this.InitializeQuery(this.CreateObjectQuery(false, new bool?(), (IDbExecutionStrategy)null));
 }
示例#2
0
        public virtual void TryInitialize()
        {
            if (this._entitySet != null)
            {
                return;
            }
            EntitySetTypePair andBaseTypeForType = base.InternalContext.TryGetEntitySetAndBaseTypeForType(typeof(TEntity));

            if (andBaseTypeForType == null)
            {
                return;
            }
            this.InitializeUnderlyingTypes(andBaseTypeForType);
        }
        // <summary>
        // Updates the cache of types to entity sets either for the first time or after potentially
        // doing some o-space loading.
        // </summary>
        private void UpdateEntitySetMappings()
        {
            var objectItemCollection = (ObjectItemCollection)_workspace.GetItemCollection(DataSpace.OSpace);
            var ospaceTypes          = _workspace.GetItems <EntityType>(DataSpace.OSpace);
            var inverseHierarchy     = new Stack <EntityType>();

            foreach (var ospaceType in ospaceTypes)
            {
                inverseHierarchy.Clear();
                var cspaceType = (EntityType)_workspace.GetEdmSpaceType(ospaceType);
                do
                {
                    inverseHierarchy.Push(cspaceType);
                    cspaceType = (EntityType)cspaceType.BaseType;
                }while (cspaceType != null);

                EntitySet entitySet = null;
                while (entitySet == null &&
                       inverseHierarchy.Count > 0)
                {
                    cspaceType = inverseHierarchy.Pop();
                    foreach (var container in _workspace.GetItems <EntityContainer>(DataSpace.CSpace))
                    {
                        var entitySets      = container.BaseEntitySets.Where(s => s.ElementType == cspaceType).ToList();
                        var entitySetsCount = entitySets.Count;
                        if (entitySetsCount > 1 ||
                            entitySetsCount == 1 && entitySet != null)
                        {
                            throw Error.DbContext_MESTNotSupported();
                        }
                        if (entitySetsCount == 1)
                        {
                            entitySet = (EntitySet)entitySets[0];
                        }
                    }
                }

                // Entity set may be null if the o-space type is a base type that is in the model but is
                // not part of any set.  For most practical purposes, this type is not in the model since
                // there is no way to query etc. for objects of this type.
                if (entitySet != null)
                {
                    var ospaceBaseType = (EntityType)_workspace.GetObjectSpaceType(cspaceType);
                    var clrType        = objectItemCollection.GetClrType(ospaceType);
                    var clrBaseType    = objectItemCollection.GetClrType(ospaceBaseType);
                    _entitySetMappingsCache[clrType] = new EntitySetTypePair(entitySet, clrBaseType);
                }
            }
        }
示例#4
0
        private void InitializeUnderlyingTypes(EntitySetTypePair pair)
        {
            DebugCheck.NotNull(pair);

            _entitySet = pair.EntitySet;
            _baseType  = pair.BaseType;

            _entitySetName = string.Format(
                CultureInfo.InvariantCulture, "{0}.{1}", _entitySet.EntityContainer.Name, _entitySet.Name);
            _quotedEntitySetName = string.Format(
                CultureInfo.InvariantCulture,
                "{0}.{1}",
                DbHelpers.QuoteIdentifier(_entitySet.EntityContainer.Name),
                DbHelpers.QuoteIdentifier(_entitySet.Name));

            InitializeQuery(CreateObjectQuery(asNoTracking: false, streaming: false));
        }