Пример #1
0
        /// <summary>
        /// Adds the row version field.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <returns>A <see cref="Zonkey.ObjectModel.IDataMapField"/> object.</returns>
        public IDataMapField AddRowVersionField(string propertyName, string fieldName)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }
            if (string.IsNullOrEmpty(fieldName))
            {
                throw new ArgumentNullException("fieldName");
            }

            PropertyInfo pi = ObjectType.GetProperty(propertyName);

            if (pi == null)
            {
                throw new ArgumentException("invalid property name");
            }

            var field = new DataMapField(pi, fieldName, DbType.Binary, false);

            field.IsRowVersion = true;
            field.Length       = 8;

            AppendField(field);
            return(field);
        }
Пример #2
0
        /// <summary>
        /// Adds the field.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="dbType">Type of the db.</param>
        /// <param name="isNullable">if set to <c>true</c>, then the database field is nullable.</param>
        /// <param name="length">The length of the field.</param>
        /// <param name="accessType">Type of the access.</param>
        /// <returns>A <see cref="Zonkey.ObjectModel.IDataMapField"/> object.</returns>
        public IDataMapField AddField(string propertyName, string fieldName, DbType dbType, bool isNullable, int length, AccessType accessType)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }
            if (string.IsNullOrEmpty(fieldName))
            {
                throw new ArgumentNullException("fieldName");
            }

            PropertyInfo pi = ObjectType.GetProperty(propertyName);

            if (pi == null)
            {
                throw new ArgumentException("invalid property name");
            }

            DataMapField field = new DataMapField(pi, fieldName, dbType, isNullable);

            field.AccessType = accessType;
            field.Length     = length;

            AppendField(field);
            return(field);
        }
Пример #3
0
        /// <summary>
        /// Adds the key field.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="dbType">Type of the db.</param>
        /// <param name="isAutoIncrement">if set to <c>true</c>, then the key field is an autoincrement field.</param>
        /// <returns>A <see cref="Zonkey.ObjectModel.IDataMapField"/> object.</returns>
        public IDataMapField AddKeyField(string propertyName, string fieldName, DbType dbType, bool isAutoIncrement)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }
            if (string.IsNullOrEmpty(fieldName))
            {
                throw new ArgumentNullException("fieldName");
            }

            PropertyInfo pi = ObjectType.GetProperty(propertyName);

            if (pi == null)
            {
                throw new ArgumentException("invalid property name");
            }

            var field = new DataMapField(pi, fieldName, dbType, false);

            field.IsAutoIncrement = isAutoIncrement;
            field.IsKeyField      = true;

            AppendField(field);
            return(field);
        }
Пример #4
0
        private static DataMap GenerateMapInternal(Type type, string tableName, IEnumerable <string> keyFields, int schemaVersion)
        {
            if (schemaVersion == 0)
            {
                schemaVersion = int.MaxValue;
            }

            var map = new DataMap(type);

            // get or create data item
            IDataMapItem theDataItem = DataItemAttribute.GetFromTypeOrMember(type);

            if (theDataItem != null)
            {
                if (!string.IsNullOrEmpty(tableName))
                {
                    theDataItem.TableName = tableName;
                }
            }
            else
            {
                theDataItem = new DataMapItem(tableName, true);
            }

            // assign to data map
            map.DataItem = theDataItem;

            // create fields from properties
            foreach (var pi in type.GetProperties())
            {
                IDataMapField field = DataFieldAttribute.GetFromProperty(pi);

                if ((field == null) && theDataItem.ImplicitFieldDefinition)
                {
                    field = new DataMapField(pi, pi.Name, DataManager.GetDbType(pi.PropertyType), true);

                    if (keyFields.Contains(field.FieldName, StringComparer.OrdinalIgnoreCase))
                    {
                        field.IsKeyField = true;
                    }

                    if ((pi.PropertyType == typeof(byte[])) && field.FieldName.Equals("rowVersion", StringComparison.OrdinalIgnoreCase))
                    {
                        field.IsRowVersion = true;
                    }
                }

                if ((field != null) && (field.SchemaVersion <= schemaVersion))
                {
                    map.AppendField(field);
                }
            }

            return(map);
        }
Пример #5
0
        /// <summary>
        /// Adds the field.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="dbType">Type of the db.</param>
        /// <returns>A <see cref="Zonkey.ObjectModel.IDataMapField"/> object.</returns>
        public IDataMapField AddField(string propertyName, string fieldName, DbType dbType)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }
            if (string.IsNullOrEmpty(fieldName))
            {
                throw new ArgumentNullException("fieldName");
            }

            PropertyInfo pi = ObjectType.GetProperty(propertyName);

            if (pi == null)
            {
                throw new ArgumentException("invalid property name");
            }

            var field = new DataMapField(pi, fieldName, dbType, true);

            AppendField(field);
            return(field);
        }