示例#1
0
        public void MappingDocSeriliazationTest()
        {
            MappingDocument mapDoc     = new MappingDocument();
            MappingElement  mapeElColl = new MappingElement();

            mapeElColl.ClassName      = "Class1";
            mapeElColl.TableName      = "Table1";
            mapeElColl.PrimaryKeyName = "Id";

            MappingRule mapEl = new MappingRule();

            mapEl.ColumnName   = "column1";
            mapEl.FieldName    = "field1";
            mapEl.DefaultValue = "somevalue";

            mapeElColl.Add(mapEl);

            mapDoc.Add(mapeElColl);

            string xml = MappingDocument.GetXml(mapDoc);

            MappingDocument loadedDoc = MappingDocument.LoadFromXml(xml);

            string xml2 = MappingDocument.GetXml(loadedDoc);

            if (xml != xml2)
            {
                throw new AssertFailedException();
            }
        }
示例#2
0
        /// <summary>
        /// Assigns the default value rule.
        /// </summary>
        /// <param name="metaFieldName">Name of the meta field.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns></returns>
        public MappingRule AssignDefaultValueRule(string metaFieldName, string defaultValue)
        {
            if (metaFieldName == null)
            {
                throw new ArgumentNullException("metaFieldName");
            }
            if (defaultValue == null)
            {
                throw new ArgumentNullException("defaultValue");
            }

            if (this.MappingDocument.Count == 0)
            {
                throw new ArgumentException("MappingDocument is empty, create MappingElement or call CreateDefaultMapping.");
            }

            //RemoveRuleByColumn(srcColumnName);
            RemoveRuleByMetaField(metaFieldName);

            MappingRule retVal = MappingRule.CreateDefaultValue(metaFieldName, defaultValue);

            MappingElement mapping = this.MappingDocument[0];

            mapping.Add(retVal);

            return(retVal);
        }