コード例 #1
0
        private void insert(DbIdentityRecordInfo info, object data)
        {
            DbFieldInfo primaryKey = info.PrimaryKey;

            if (primaryKey.FieldType == typeof(Guid))
            {
                Guid guid = Guid.NewGuid();
                primaryKey.SetValue(data, guid);

                object[] values = info.GetValues(data, primaryKey.Name, guid);
                Accessor.Insert(info.TableName, values);
            }
            else
            if (!info.IsDbGeneratedPrimaryKey)
            {
                object[] values = info.GetValues(data, primaryKey.Name, primaryKey.GetValue(data));
                Accessor.Insert(info.TableName, values);
            }
            else
            {
                object[] values = info.GetValues(data);
                object   newId  = Accessor.InsertIdentity(info.TableName, primaryKey.Name, values);
                primaryKey.SetValue(data, Convert.ChangeType(newId, primaryKey.FieldType));
            }
        }
コード例 #2
0
        /// <summary>
        /// Remove object from database
        /// </summary>
        /// <param name="data">an object with DbAttributes</param>
        /// <returns>true if one object has been removed</returns>
        public bool Delete(object data)
        {
            var info = DbAttributesManager.GetRecordInfo(data.GetType());

            var identityRecordInfo = info as DbIdentityRecordInfo;

            if (identityRecordInfo != null)
            {
                DbFieldInfo primaryKey = identityRecordInfo.PrimaryKey;

                return(0 < Accessor.Delete(
                           info.TableName,
                           primaryKey.Name,
                           primaryKey.GetValue(data)));
            }

            return(1 < DeleteByAllFields(data));
        }
コード例 #3
0
        public bool IsPrimaryKeyValid(object data)
        {
            var primaryKey = PrimaryKey.GetValue(data);

            return(!IsNull(primaryKey));
        }