// effects: Given a type, determines all possible values that can be created from Metadata
        private static CellConstantSet DeriveDomainFromType(EdmType type, EdmItemCollection edmItemCollection, bool leaveDomainUnbounded)
        {
            CellConstantSet domain = null;

            if (Helper.IsScalarType(type))
            {                
                // Get the domain for scalars -- for booleans, we special case. 
                if (MetadataHelper.HasDiscreteDomain(type))
                {
                    Debug.Assert(Helper.AsPrimitive(type).PrimitiveTypeKind == PrimitiveTypeKind.Boolean, "Only boolean type has discrete domain.");

                    // Closed domain
                    domain = new Set<Constant>(CreateList(true, false), Constant.EqualityComparer);
                }
                else
                {
                    // Unbounded domain
                    domain = new Set<Constant>(Constant.EqualityComparer);
                    if (leaveDomainUnbounded)
                    {
                        domain.Add(Constant.NotNull);
                    }
                }
            }
            else //Type Constants - Domain is all possible concrete subtypes
            {
                Debug.Assert(Helper.IsEntityType(type) || Helper.IsComplexType(type) || Helper.IsRefType(type) || Helper.IsAssociationType(type));

                // Treat ref types as their referenced entity types
                if (Helper.IsRefType(type))
                {
                    type = ((RefType)type).ElementType;
                }

                List<Constant> types = new List<Constant>();
                foreach (EdmType derivedType in MetadataHelper.GetTypeAndSubtypesOf(type, edmItemCollection, false /*includeAbstractTypes*/))
                {
                    TypeConstant derivedTypeConstant = new TypeConstant(derivedType);
                    types.Add(derivedTypeConstant);
                }
                domain = new Set<Constant>(types, Constant.EqualityComparer);
            }

            Debug.Assert(domain != null, "Domain not set up for some type");
            return domain;
        }
 // for backward compatibility: add (WHEN True THEN Type) for non-scalar types
 internal void AddTrivialCaseStatementsForConditionMembers()
 {
     for (var memberNum = 0; memberNum < _context.MemberMaps.ProjectedSlotMap.Count; memberNum++)
     {
         var memberPath = _context.MemberMaps.ProjectedSlotMap[memberNum];
         if (!memberPath.IsScalarType()
             && !_caseStatements.ContainsKey(memberPath))
         {
             Constant typeConstant = new TypeConstant(memberPath.EdmType);
             {
                 var caseStmt = new CaseStatement(memberPath);
                 caseStmt.AddWhenThen(BoolExpression.True, new ConstantProjectedSlot(typeConstant));
                 _caseStatements[memberPath] = caseStmt;
             }
         }
     }
 }