예제 #1
0
파일: MiscUtils.cs 프로젝트: mjaric/nfx
        /// <summary>
        /// Copies reader fields into record fields finding matches by name and store flag.
        /// Reader must be in a "readable" state - "reader.Read()" should be executed by the caller
        /// <code>
        ///   if (reader.Read()) reader.CopyFieldsToRecordFields(record);
        /// </code>
        /// </summary>
        public static void CopyFieldsToRecordFields(this DbDataReader reader, RecordModel.Record record)
        {
            for (int i = 0; i < reader.FieldCount; i++)
            {
                var val = reader.GetValue(i);

                var fld = record.FindFieldByName(reader.GetName(i));

                if (fld == null)
                {
                    continue;
                }

                if (fld.StoreFlag == DataAccess.StoreFlag.LoadAndStore || fld.StoreFlag == DataAccess.StoreFlag.OnlyLoad)
                {
                    if (val == DBNull.Value)
                    {
                        fld.ValueAsObject = null; //same as field.Clear();
                    }
                    else
                    {
                        fld.ValueAsObject = val;
                    }
                }
            }
        }
예제 #2
0
파일: Record.cs 프로젝트: rioka/nfx
        public void ValidationExceptionOnPost()
        {
            var rec = R.Make <PersonRecord>();

            rec.Create();
            rec.fldRegistered.Value = true;
            rec.Post();//rest of required fields are blank
        }
예제 #3
0
파일: Record.cs 프로젝트: rioka/nfx
        private PersonRecord makeValidPerson()
        {
            var rec = R.Make <PersonRecord>();

            rec.Create();
            rec.fldName.Value       = "John Frank Bookman";
            rec.fldScore.Value      = 10;
            rec.fldSex.Value        = "M";
            rec.fldSalary.Value     = 75000M;
            rec.fldRegistered.Value = true;
            rec.fldDOB.Value        = DateTime.Parse("June 18, 1955");
            rec.fldMovieNames.Value.Add("Titanic");

            return(rec);
        }
예제 #4
0
파일: Record.cs 프로젝트: rioka/nfx
        public void DefaultValues()
        {
            var rec = R.Make <PersonRecord>();

            //this is black magic, never cast fields in normal use cases
            var fldName = (StringField)rec.fldName;

            fldName.DefaultValue    = "Hello!";
            fldName.HasDefaultValue = true;

            var fldRegistered = (BoolField)rec.fldRegistered;

            fldRegistered.DefaultValue    = false;
            fldRegistered.HasDefaultValue = true;

            rec.Create();//this should default field values

            Assert.AreEqual("Hello!", ~fldName);
            Assert.IsTrue(rec.fldName.HasValue);

            Assert.IsFalse(~fldRegistered);
            Assert.IsTrue(rec.fldName.HasValue);
        }
예제 #5
0
파일: Record.cs 프로젝트: rioka/nfx
        public void ListOfTFieldImmutability()
        {
            var rec = R.Make <PersonRecord>();

            rec.fldMovieNames.Value.Add("cant go");
        }
예제 #6
0
파일: Record.cs 프로젝트: rioka/nfx
        public void StateExceptionOnMutation()
        {
            var rec = R.Make <PersonRecord>();

            rec.fldName.Value = "aaa"; //cant write to non-init record
        }