예제 #1
0
        /// <summary>
        /// Saves a child object to the TextBase stream.
        /// </summary>
        /// <returns>The child object converted to a TableRecord string.</returns>
        /// <param name="parentID">The ID of the parent object.</param>
        /// <param name="obj">The C# object to save.</param>
        /// <param name="requireForeignKey">If set to <c>true</c>, requires a foreign key.</param>
        internal string SaveChild(string parentID, object obj, bool requireForeignKey)
        {
            // Load the schema
            var type   = obj.GetType();
            var schema = GetSchema(type);

            // Is a foreign key required?
            if (requireForeignKey)
            {
                if (schema.ForeignKey == null)
                {
                    throw new MissingForeignKeyException(string.Format("Class {0} has not defined the required ForeignKey attribute that is required to be used in a List marked with the Children attribute.", schema.TableName));
                }
                else
                {
                    // Save the parent ID
                    UpdateForeignKey(obj, type, schema, parentID);
                }
            }

            // Get the current record ID
            var recordID = PrimaryKey(obj, type, schema);

            // Convert to table record
            var record = new TextBaseRecord(schema.TableName, ClassToRecord(schema, obj));

            // Return record
            return(record);
        }
예제 #2
0
        /// <summary>
        /// Save the specified obj and type to the TextBase database.
        /// </summary>
        /// <param name="obj">The C# object to save.</param>
        /// <param name="type">The object's type.</param>
        internal string Save(object obj, Type type)
        {
            // Load the schema
            var schema = GetSchema(type);

            // Get the current record ID
            var recordID = PrimaryKey(obj, type, schema);

            // Convert to TextBase record
            var record = new TextBaseRecord(schema.TableName, ClassToRecord(schema, obj));

            // Return resulting record
            return(record);
        }