Example #1
0
        internal static TypeUsage ValidateCreateRef(
            EntitySet entitySet,
            EntityType entityType,
            IEnumerable <DbExpression> keyValues,
            out DbExpression keyConstructor)
        {
            ArgumentValidation.CheckEntitySet((EntitySetBase)entitySet, nameof(entitySet));
            ArgumentValidation.CheckType((EdmType)entityType, nameof(entityType));
            if (!TypeSemantics.IsValidPolymorphicCast((EdmType)entitySet.ElementType, (EdmType)entityType))
            {
                throw new ArgumentException(Strings.Cqt_Ref_PolymorphicArgRequired);
            }
            IList <EdmMember> keyMembers = (IList <EdmMember>)entityType.KeyMembers;
            EnumerableValidator <DbExpression, KeyValuePair <string, DbExpression>, List <KeyValuePair <string, DbExpression> > > validator = ArgumentValidation.CreateValidator <DbExpression, KeyValuePair <string, DbExpression>, List <KeyValuePair <string, DbExpression> > >(keyValues, nameof(keyValues), (Func <DbExpression, int, KeyValuePair <string, DbExpression> >)((valueExp, idx) =>
            {
                ArgumentValidation.RequireCompatibleType(valueExp, keyMembers[idx].TypeUsage, nameof(keyValues), idx);
                return(new KeyValuePair <string, DbExpression>(keyMembers[idx].Name, valueExp));
            }), (Func <List <KeyValuePair <string, DbExpression> >, List <KeyValuePair <string, DbExpression> > >)(columnList => columnList));

            validator.ExpectedElementCount = keyMembers.Count;
            List <KeyValuePair <string, DbExpression> > keyValuePairList = validator.Validate();

            keyConstructor = (DbExpression)DbExpressionBuilder.NewRow((IEnumerable <KeyValuePair <string, DbExpression> >)keyValuePairList);
            return(ArgumentValidation.CreateReferenceResultType((EntityTypeBase)entityType));
        }
Example #2
0
        internal static TypeUsage ValidateRefFromKey(
            EntitySet entitySet,
            DbExpression keyValues,
            EntityType entityType)
        {
            ArgumentValidation.CheckEntitySet((EntitySetBase)entitySet, nameof(entitySet));
            ArgumentValidation.CheckType((EdmType)entityType);
            if (!TypeSemantics.IsValidPolymorphicCast((EdmType)entitySet.ElementType, (EdmType)entityType))
            {
                throw new ArgumentException(Strings.Cqt_Ref_PolymorphicArgRequired);
            }
            TypeUsage resultType = ArgumentValidation.CreateResultType((EdmType)TypeHelpers.CreateKeyRowType((EntityTypeBase)entitySet.ElementType));

            ArgumentValidation.RequireCompatibleType(keyValues, resultType, nameof(keyValues));
            return(ArgumentValidation.CreateReferenceResultType((EntityTypeBase)entityType));
        }
 internal DbTreatExpression(TypeUsage asType, DbExpression argument)
     : base(DbExpressionKind.Treat, asType, argument)
 {
     Debug.Assert(TypeSemantics.IsValidPolymorphicCast(argument.ResultType, asType), "DbTreatExpression represents an invalid treat");
 }