private string GetFacetString(EdmProperty column)
        {
            StringBuilder sql = new StringBuilder();
            Facet facet;
            ReadOnlyMetadataCollection<Facet> facets = column.TypeUsage.Facets;

            if (column.TypeUsage.EdmType.BaseType.Name == "String")
            {
                if (facets.TryGetValue("MaxLength", true, out facet))
                    sql.AppendFormat(" ({0})", facet.Value);
            }
            if (facets.TryGetValue("Nullable", true, out facet) && (bool)facet.Value == false)
                sql.Append(" NOT NULL");
            if (facets.TryGetValue("StoreGeneratedPattern", true, out facet) && facet.Value.Equals(StoreGeneratedPattern.Identity))
                sql.Append(" AUTO_INCREMENT PRIMARY KEY");
            return sql.ToString();
        }
Esempio n. 2
0
        internal override int GetOrdinalforCLayerName(string name, StateManagerTypeMetadata metadata)
        {
            ReadOnlyMetadataCollection <AssociationEndMember> associationEndMembers = this._relationshipWrapper.AssociationEndMembers;
            AssociationEndMember associationEndMember;

            if (associationEndMembers.TryGetValue(name, false, out associationEndMember))
            {
                return(associationEndMembers.IndexOf(associationEndMember));
            }
            return(-1);
        }
Esempio n. 3
0
        private string GetFacetString(EdmProperty column, bool IsKeyMember)
        {
            StringBuilder sql = new StringBuilder();
            Facet         facet;
            Facet         fcDateTimePrecision = null;

            ReadOnlyMetadataCollection <Facet> facets = column.TypeUsage.Facets;

            if (column.TypeUsage.EdmType.BaseType.Name == "String")
            {
                // types tinytext, mediumtext, text & longtext don't have a length.
                if (!column.TypeUsage.EdmType.Name.EndsWith("text", StringComparison.OrdinalIgnoreCase))
                {
                    if (facets.TryGetValue("MaxLength", true, out facet))
                    {
                        sql.AppendFormat(" ({0})", facet.Value);
                    }
                }
            }
            else if (column.TypeUsage.EdmType.BaseType.Name == "Decimal")
            {
                Facet fcScale;
                Facet fcPrecision;
                if (facets.TryGetValue("Scale", true, out fcScale) && facets.TryGetValue("Precision", true, out fcPrecision))
                {
                    // Enforce scale to a reasonable value.
                    int scale = fcScale.Value == null ? 0 : ( int )( byte )fcScale.Value;
                    if (scale == 0)
                    {
                        scale = MySqlProviderManifest.DEFAULT_DECIMAL_SCALE;
                    }
                    sql.AppendFormat("( {0}, {1} ) ", fcPrecision.Value, scale);
                }
            }
            else if (column.TypeUsage.EdmType.BaseType.Name == "DateTime")
            {
                if (serverVersion >= new Version(5, 6) && facets.TryGetValue("Precision", true, out fcDateTimePrecision))
                {
                    if (Convert.ToByte(fcDateTimePrecision.Value) >= 1)
                    {
                        sql.AppendFormat("( {0} ) ", fcDateTimePrecision.Value);
                    }
                }
            }


            if (facets.TryGetValue("Nullable", true, out facet) && (bool)facet.Value == false)
            {
                sql.Append(" NOT NULL");
            }

            if (facets.TryGetValue("StoreGeneratedPattern", true, out facet))
            {
                if (facet.Value.Equals(StoreGeneratedPattern.Identity))
                {
                    if (column.TypeUsage.EdmType.BaseType.Name.StartsWith("Int"))
                    {
                        sql.Append(" AUTO_INCREMENT UNIQUE");
                    }
                    else if (column.TypeUsage.EdmType.BaseType.Name == "Guid")
                    {
                        _guidIdentityColumns.Add(column.Name);
                    }
                    else if (serverVersion >= new Version(5, 6) && column.TypeUsage.EdmType.BaseType.Name == "DateTime")
                    {
                        sql.AppendFormat(" DEFAULT CURRENT_TIMESTAMP{0}", fcDateTimePrecision != null && Convert.ToByte(fcDateTimePrecision.Value) >= 1 ? "( " + fcDateTimePrecision.Value.ToString() + " )" : "");
                    }
                    else
                    {
                        throw new MySqlException("Invalid identity column type.");
                    }
                }
            }
            return(sql.ToString());
        }
Esempio n. 4
0
        public override TypeUsage GetStoreType(TypeUsage edmType)
        {
            if (edmType == null)
            {
                throw new ArgumentNullException("edmType");
            }

            System.Diagnostics.Debug.Assert(edmType.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType);

            PrimitiveType primitiveType = edmType.EdmType as PrimitiveType;

            if (primitiveType == null)
            {
                throw new ArgumentException(String.Format("The underlying provider does not support the type '{0}'.", edmType));
            }

            ReadOnlyMetadataCollection <Facet> facets = edmType.Facets;
            Facet f;

            switch (primitiveType.PrimitiveTypeKind)
            {
            case PrimitiveTypeKind.Boolean:
                return(TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["boolean"]));

            case PrimitiveTypeKind.Byte:
            case PrimitiveTypeKind.Int16:
                return(TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["smallint"]));

            case PrimitiveTypeKind.Int32:
                return(TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["integer"]));

            case PrimitiveTypeKind.Int64:
                return(TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["bigint"]));

            case PrimitiveTypeKind.Double:
                return(TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["double"]));

            case PrimitiveTypeKind.Single:
                return(TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["float"]));

            case PrimitiveTypeKind.Decimal:     // decimal, numeric
            {
                byte precision = 9;
                if (facets.TryGetValue("Precision", false, out f) && !f.IsUnbounded && f.Value != null)
                {
                    precision = (byte)f.Value;
                }
                byte scale = 0;
                if (facets.TryGetValue("Scale", false, out f) && !f.IsUnbounded && f.Value != null)
                {
                    scale = (byte)f.Value;
                }

                return(TypeUsage.CreateDecimalTypeUsage(StoreTypeNameToStorePrimitiveType["decimal"], precision, scale));
            }

            case PrimitiveTypeKind.String:     // char, varchar, text blob
            {
                bool isUnicode = true;
                if (facets.TryGetValue("Unicode", false, out f) && !f.IsUnbounded && f.Value != null)
                {
                    isUnicode = (bool)f.Value;
                }
                bool isFixedLength = true;
                if (facets.TryGetValue("FixedLength", false, out f) && !f.IsUnbounded && f.Value != null)
                {
                    isFixedLength = (bool)f.Value;
                }
                int maxLength = Int32.MinValue;
                if (facets.TryGetValue("MaxLength", false, out f) && !f.IsUnbounded && f.Value != null)
                {
                    maxLength = (int)f.Value;
                }

                PrimitiveType storePrimitiveType = StoreTypeNameToStorePrimitiveType[isFixedLength ? "char" : "varchar"];
                if (maxLength != Int32.MinValue)
                {
                    return(TypeUsage.CreateStringTypeUsage(storePrimitiveType, isUnicode, isFixedLength, maxLength));
                }

                return(TypeUsage.CreateStringTypeUsage(storePrimitiveType, isUnicode, isFixedLength));
            }

            case PrimitiveTypeKind.DateTime:     // datetime, date
            {
                byte precision = 4;
                if (facets.TryGetValue("Precision", false, out f) && !f.IsUnbounded && f.Value != null)
                {
                    precision = (byte)f.Value;
                }

                bool useTimestamp = (precision != 0);

                return(TypeUsage.CreateDefaultTypeUsage(useTimestamp ? StoreTypeNameToStorePrimitiveType["datetime"] : StoreTypeNameToStorePrimitiveType["date"]));
            }

            case PrimitiveTypeKind.Time:
                return(TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["time"]));

            case PrimitiveTypeKind.Binary:     // blob
            {
                bool isFixedLength = true;
                if (facets.TryGetValue("FixedLength", false, out f) && !f.IsUnbounded && f.Value != null)
                {
                    isFixedLength = (bool)f.Value;
                }
                int maxLength = Int32.MinValue;
                if (facets.TryGetValue("MaxLength", false, out f) && !f.IsUnbounded && f.Value != null)
                {
                    maxLength = (int)f.Value;
                }

                PrimitiveType storePrimitiveType = StoreTypeNameToStorePrimitiveType["binary"];
                if (maxLength != Int32.MinValue)
                {
                    return(TypeUsage.CreateBinaryTypeUsage(storePrimitiveType, isFixedLength, maxLength));
                }

                return(TypeUsage.CreateBinaryTypeUsage(storePrimitiveType, isFixedLength));
            }

            case PrimitiveTypeKind.Guid:
                return(TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["guid_char"]));

            default:
                throw new NotSupportedException(string.Format("There is no store type corresponding to the EDM type '{0}' of primitive type '{1}'.", edmType, primitiveType.PrimitiveTypeKind));
            }
        }