Exemple #1
0
        internal object Execute(ITableRow row)
        {
            this.connection.StartTransaction(System.Data.IsolationLevel.ReadCommitted);

            // Save the blob first
            if (table.BlobValueColumn != null && table.BlobNameColumn != null)
            {
                object guidObject = null;
                Guid   blobName   = Guid.Empty;
                if (!row.ColumnValues.TryGetValue(table.BlobNameColumn, out guidObject))
                {
                    blobName = Guid.NewGuid();
                    row.ColumnValues.Add(table.BlobNameColumn, blobName);
                }
                else
                {
                    blobName = (Guid)guidObject;
                }

                object blobValue = null;
                if (!row.ColumnValues.TryGetValue(table.BlobValueColumn, out blobValue))
                {
                    row.ColumnValues[table.BlobNameColumn] = Guid.Empty;
                    blobName = Guid.Empty;
                }

                IBlobStore blobStore = BlobStoreFactory.Instance.GetBlobStore();
                blobStore.SaveBlob(row.BlobContainer, blobName.ToString(), (byte[])blobValue);
            }

            // Save the row in the table
            DbCommand command = this.BuildInsertCommand(row);

            if (table.Identity != null)
            {
                SqlParameter outParameter = new SqlParameter(string.Format("@{0}", table.Identity.Name), DatabaseInsertOperator.GetSqlType(table.Identity.Type));
                outParameter.Direction = ParameterDirection.Output;
                command.Parameters.Add(outParameter);
            }

            object outParam = command.ExecuteScalar();

            this.connection.CommitTransaction();

            return(null);
        }