示例#1
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));
        }
示例#2
0
        private System.Data.Entity.Core.Objects.ObjectQuery <TEntity> BuildFindQuery(
            WrappedEntityKey key)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat("SELECT VALUE X FROM {0} AS X WHERE ", (object)this.QuotedEntitySetName);
            EntityKeyMember[] entityKeyValues      = key.EntityKey.EntityKeyValues;
            ObjectParameter[] objectParameterArray = new ObjectParameter[entityKeyValues.Length];
            for (int index = 0; index < entityKeyValues.Length; ++index)
            {
                if (index > 0)
                {
                    stringBuilder.Append(" AND ");
                }
                string name = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "p{0}", (object)index.ToString((IFormatProvider)CultureInfo.InvariantCulture));
                stringBuilder.AppendFormat("X.{0} = @{1}", (object)DbHelpers.QuoteIdentifier(entityKeyValues[index].Key), (object)name);
                objectParameterArray[index] = new ObjectParameter(name, entityKeyValues[index].Value);
            }
            return(this.InternalContext.ObjectContext.CreateQuery <TEntity>(stringBuilder.ToString(), objectParameterArray));
        }
示例#3
0
        private ObjectQuery<TEntity> BuildFindQuery(WrappedEntityKey key)
        {
            var queryBuilder = new StringBuilder();
            queryBuilder.AppendFormat("SELECT VALUE X FROM {0} AS X WHERE ", QuotedEntitySetName);

            var entityKeyValues = key.EntityKey.EntityKeyValues;
            var parameters = new ObjectParameter[entityKeyValues.Length];

            for (var i = 0; i < entityKeyValues.Length; i++)
            {
                if (i > 0)
                {
                    queryBuilder.Append(" AND ");
                }

                var name = string.Format(CultureInfo.InvariantCulture, "p{0}", i.ToString(CultureInfo.InvariantCulture));
                queryBuilder.AppendFormat("X.{0} = @{1}", DbHelpers.QuoteIdentifier(entityKeyValues[i].Key), name);
                parameters[i] = new ObjectParameter(name, entityKeyValues[i].Value);
            }

            return InternalContext.ObjectContext.CreateQuery<TEntity>(queryBuilder.ToString(), parameters);
        }
示例#4
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));
 }