コード例 #1
0
        public static FileGroupField GetOrAdd(this TableOperations <FileGroupField> fileGroupFieldTable, string name, string description = null)
        {
            FileGroupField fileGroupField = fileGroupFieldTable.QueryRecordWhere("Name = {0}", name);

            if ((object)fileGroupField == null)
            {
                fileGroupField             = new FileGroupField();
                fileGroupField.Name        = name;
                fileGroupField.Description = description;

                try
                {
                    fileGroupFieldTable.AddNewRecord(fileGroupField);
                }
                catch (Exception ex)
                {
                    // Ignore errors regarding unique key constraints
                    // which can occur as a result of a race condition
                    bool isUniqueViolation = ExceptionHandler.IsUniqueViolation(ex);

                    if (!isUniqueViolation)
                    {
                        throw;
                    }

                    return(fileGroupFieldTable.QueryRecordWhere("Name = {0}", name));
                }

                fileGroupField.ID = fileGroupFieldTable.Connection.ExecuteScalar <int>("SELECT @@IDENTITY");
            }

            return(fileGroupField);
        }
コード例 #2
0
        public void AddFieldValue(AdoDataConnection connection, string name, string value, string description = null)
        {
            TableOperations <FileGroupField> fileGroupFieldTable = new TableOperations <FileGroupField>(connection);
            FileGroupField fileGroupField = fileGroupFieldTable.GetOrAdd(name, description);

            TableOperations <FileGroupFieldValue> fileGroupFieldValueTable = new TableOperations <FileGroupFieldValue>(connection);
            FileGroupFieldValue fileGroupFieldValue = new FileGroupFieldValue();

            fileGroupFieldValue.FileGroupID      = ID;
            fileGroupFieldValue.FileGroupFieldID = fileGroupField.ID;
            fileGroupFieldValue.Value            = value;
            fileGroupFieldValueTable.AddNewRecord(fileGroupFieldValue);
        }