Exemplo n.º 1
0
        /// <summary>
        /// Make data property metadata for the entity
        /// </summary>
        /// <param name="propName">name of the property on the server</param>
        /// <param name="type">data type of the property, e.g. Int32</param>
        /// <param name="isNullable">whether the property is nullable in the database</param>
        /// <param name="isKey">true if this property is part of the key for the entity</param>
        /// <param name="isVersion">true if this property contains the version of the entity (for a concurrency strategy)</param>
        /// <returns></returns>
        private MetaDataProperty MakeDataProperty(string propName, IType type, bool isNullable, bool isKey, bool isVersion)
        {
            string newType;
            var    typeName = (BreezeTypeMap.TryGetValue(type.Name, out newType)) ? newType : type.Name;

            var dmap = new MetaDataProperty {
                NameOnServer = propName,
                DataType     = typeName,
                IsNullable   = isNullable
            };


            var sqlTypes = type.SqlTypes((ISessionFactoryImplementor)this._sessionFactory);
            var sqlType  = sqlTypes[0];

            // This doesn't work; NH does not pick up the default values from the property/column definition
            //if (type is PrimitiveType && !(type is DateTimeOffsetType))
            //{
            //    var def = ((PrimitiveType)type).DefaultValue;
            //    if (def != null && def.ToString() != "0")
            //        dmap.Add("defaultValue", def);
            //}

            if (isKey)
            {
                dmap.IsPartOfKey = true;
            }
            if (isVersion)
            {
                dmap.ConcurrencyMode = "Fixed";
            }

            if (!isNullable)
            {
                dmap.Validators.Add(MetaValidator.Required);
            }
            if (sqlType.LengthDefined)
            {
                dmap.MaxLength = sqlType.Length;
                dmap.Validators.Add(new MaxLengthMetaValidator(sqlType.Length));
            }

            var validator = MetaValidator.FindValidator(type.ReturnedClass);

            if (validator != null)
            {
                dmap.Validators.Add(validator);
            }

            return(dmap);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Make data property metadata for the entity
        /// </summary>
        /// <param name="propName">name of the property on the server</param>
        /// <param name="typeName">data type of the property, e.g. Int32</param>
        /// <param name="isNullable">whether the property is nullable in the database</param>
        /// <param name="col">Column object, used for maxLength and defaultValue</param>
        /// <param name="isKey">true if this property is part of the key for the entity</param>
        /// <param name="isVersion">true if this property contains the version of the entity (for a concurrency strategy)</param>
        /// <returns></returns>
        private Dictionary <string, object> MakeDataProperty(string propName, string typeName, bool isNullable, Column col, bool isKey, bool isVersion)
        {
            string newType;

            typeName = (BreezeTypeMap.TryGetValue(typeName, out newType)) ? newType : typeName;

            var dmap = new Dictionary <string, object>();

            dmap.Add("nameOnServer", propName);
            dmap.Add("dataType", typeName);
            dmap.Add("isNullable", isNullable);

            if (col != null && col.DefaultValue != null)
            {
                dmap.Add("defaultValue", col.DefaultValue);
            }
            if (isKey)
            {
                dmap.Add("isPartOfKey", true);
            }
            if (isVersion)
            {
                dmap.Add("concurrencyMode", "Fixed");
            }

            var validators = new List <Dictionary <string, string> >();

            if (!isNullable)
            {
                validators.Add(new Dictionary <string, string>()
                {
                    { "name", "required" },
                });
            }
            if (col != null && col.IsLengthDefined())
            {
                dmap.Add("maxLength", col.Length);

                validators.Add(new Dictionary <string, string>()
                {
                    { "maxLength", col.Length.ToString() },
                    { "name", "maxLength" }
                });
            }

            string validationType;

            if (ValidationTypeMap.TryGetValue(typeName, out validationType))
            {
                validators.Add(new Dictionary <string, string>()
                {
                    { "name", validationType },
                });
            }

            if (validators.Any())
            {
                dmap.Add("validators", validators);
            }

            return(dmap);
        }
        /// <summary>
        /// Make data property metadata for the entity
        /// </summary>
        /// <param name="propName">name of the property on the server</param>
        /// <param name="type">data type of the property, e.g. Int32</param>
        /// <param name="isNullable">whether the property is nullable in the database</param>
        /// <param name="isKey">true if this property is part of the key for the entity</param>
        /// <param name="isVersion">true if this property contains the version of the entity (for a concurrency strategy)</param>
        /// <returns></returns>
        private Dictionary <string, object> MakeDataProperty(string propName, IType type, bool isNullable, bool isKey, bool isVersion)
        {
            string newType;
            var    typeName = (BreezeTypeMap.TryGetValue(type.Name, out newType)) ? newType : type.Name;

            var dmap = new Dictionary <string, object>();

            dmap.Add("nameOnServer", propName);
            dmap.Add("dataType", typeName);
            dmap.Add("isNullable", isNullable);

            var sqlTypes = type.SqlTypes((ISessionFactoryImplementor)this._sessionFactory);
            var sqlType  = sqlTypes[0];

            // This doesn't work; NH does not pick up the default values from the property/column definition
            //if (type is PrimitiveType && !(type is DateTimeOffsetType))
            //{
            //    var def = ((PrimitiveType)type).DefaultValue;
            //    if (def != null && def.ToString() != "0")
            //        dmap.Add("defaultValue", def);
            //}

            if (isKey)
            {
                dmap.Add("isPartOfKey", true);
            }
            if (isVersion)
            {
                dmap.Add("concurrencyMode", "Fixed");
            }

            var validators = new List <Dictionary <string, object> >();

            if (!isNullable)
            {
                validators.Add(new Dictionary <string, object>()
                {
                    { "name", "required" },
                });
            }
            if (sqlType.LengthDefined)
            {
                dmap.Add("maxLength", sqlType.Length);

                validators.Add(new Dictionary <string, object>()
                {
                    { "maxLength", sqlType.Length },
                    { "name", "maxLength" }
                });
            }

            string validationType;

            if (ValidationTypeMap.TryGetValue(typeName, out validationType))
            {
                validators.Add(new Dictionary <string, object>()
                {
                    { "name", validationType },
                });
            }

            if (validators.Any())
            {
                dmap.Add("validators", validators);
            }

            return(dmap);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Make data property metadata for the entity
        /// </summary>
        /// <param name="propName">name of the property on the server</param>
        /// <param name="type">data type of the property, e.g. Int32</param>
        /// <param name="isNullable">whether the property is nullable in the database</param>
        /// <param name="isKey">true if this property is part of the key for the entity</param>
        /// <param name="isVersion">true if this property contains the version of the entity (for a concurrency strategy)</param>
        /// <returns></returns>
        private Dictionary <string, object> MakeDataProperty(string propName, IType type, bool isNullable, bool isKey, bool isVersion)
        {
            string newType;
            var    typeName = (BreezeTypeMap.TryGetValue(type.Name, out newType)) ? newType : type.Name;

            var dmap = new Dictionary <string, object>();

            dmap.Add("nameOnServer", propName);
            dmap.Add("dataType", typeName);
            dmap.Add("isNullable", isNullable);

            var sqlTypes = type.SqlTypes((ISessionFactoryImplementor)this._sessionFactory);
            var sqlType  = sqlTypes[0];

            //if (col != null && col.DefaultValue != null)
            //{
            //    dmap.Add("defaultValue", col.DefaultValue);
            //}
            if (isKey)
            {
                dmap.Add("isPartOfKey", true);
            }
            if (isVersion)
            {
                dmap.Add("concurrencyMode", "Fixed");
            }

            var validators = new List <Dictionary <string, string> >();

            if (!isNullable)
            {
                validators.Add(new Dictionary <string, string>()
                {
                    { "name", "required" },
                });
            }
            if (sqlType.LengthDefined)
            {
                dmap.Add("maxLength", sqlType.Length);

                validators.Add(new Dictionary <string, string>()
                {
                    { "maxLength", sqlType.Length.ToString() },
                    { "name", "maxLength" }
                });
            }

            string validationType;

            if (ValidationTypeMap.TryGetValue(typeName, out validationType))
            {
                validators.Add(new Dictionary <string, string>()
                {
                    { "name", validationType },
                });
            }

            if (validators.Any())
            {
                dmap.Add("validators", validators);
            }

            return(dmap);
        }