Exemple #1
0
        public static void ReadUpdatedRowVersion(this DbCommand command, ILinq2SqlEntity entity, string tableName, string rowIdColumn = "oid", string rowVersionColumn = "version")
        {
            var commandText = string.Format("SELECT [{1}] FROM [{2}] WHERE [{0}] = @id", rowIdColumn, rowVersionColumn, tableName);

            using (var cmd = CreateCommand(command.Connection, commandText, command.Transaction))
            {
                cmd.SetParameter("id", entity.RowId);
                entity.RowVersion = ToLinqBinary(cmd.ExecuteScalar());
            }
        }
Exemple #2
0
        public static void ReadInsertedRowIdentity(this DbCommand command, ILinq2SqlEntity entity, string tableName, string rowIdColumn = "oid", string rowVersionColumn = "version")
        {
            var commandText = string.Format("SELECT [{1}] FROM [{2}] WHERE [{0}] = @id", rowIdColumn, rowVersionColumn, tableName);

            using (var cmd = CreateCommand(command.Connection, "SELECT @@IDENTITY", command.Transaction))
            {
                // executing a scalar command twice is significantly faster then executing a reader query for a two-column-single-row result
                entity.RowId    = Convert.ToInt64(cmd.ExecuteScalar());
                cmd.CommandText = commandText;
                cmd.SetParameter("id", entity.RowId);
                entity.RowVersion = ToLinqBinary(cmd.ExecuteScalar());
            }
        }