Пример #1
0
        internal static Result <T> InsertGo <T>(Assembly client, DbRow row, bool identityInsert, ConnectBy connectBy)
            where T : DbRow
        {
            var name = Text.NotAvailable;

            try
            {
                var connectable = GetInsertBody <T>(client, row, identityInsert, connectBy, Text.Method.InsertGo, ref name);
                var result      = connectable.Go <T>();
                if (result.RowCount > 0)
                {
                    PropertyAccessor.SetValues(row, PropertyAccessor.GetValues(result.First()));
                    row.SetStatus(DbRowStatus.Loaded);

                    // has rowversion & it is not RK
                    if (row.HasNonRKRowversion)
                    {
                        Crud.ReloadGo <T>(client, row, false, connectBy, true);
                    }
                    else
                    {
                        // rowversion column is null:
                        var map = DbMapping.TryGetNodeMap(row);
                        if (map.HasRowversion && row.GetRowversionValue() == null)
                        {
                            row.SetStatus(DbRowStatus.Faulted);
                        }
                        else
                        {
                            row.SetStatus(DbRowStatus.Loaded);
                        }
                    }
                }

                result.FinalizeCrud();
                return(result);
            }
            catch (QueryTalkException)
            {
                throw;
            }
            catch (System.Exception ex)
            {
                throw Crud.ClrException(ex, name, Text.Method.InsertGo);
            }
        }
Пример #2
0
        internal static Result <T> UpdateGo <T>(Assembly client, DbRow row, bool forceMirroring, ConnectBy connectBy)
            where T : DbRow
        {
            var     name = Text.NotAvailable;
            NodeMap map;

            try
            {
                var connectable = GetUpdateBody <T>(client, row, forceMirroring, connectBy, Text.Method.UpdateGo, ref name, out map);

                // no columns to modify?
                if (connectable == null)
                {
                    return(new Result <T>(false, 0));
                }

                var result = connectable.Go <T>();

                // success
                if (result.ReturnValue == 1)
                {
                    PropertyAccessor.SetValues(row, PropertyAccessor.GetValues(result.First()));

                    // has rowversion & it is not RK
                    if (row.HasNonRKRowversion)
                    {
                        row.SetStatus(DbRowStatus.Loaded);
                        Crud.ReloadGo <T>(client, row, true, connectBy, true);
                    }
                    else
                    {
                        // rowversion column is null:
                        if (map.HasRowversion && row.GetRowversionValue() == null)
                        {
                            row.SetStatus(DbRowStatus.Faulted);
                        }
                        else
                        {
                            row.SetStatus(DbRowStatus.Loaded);
                        }
                    }

                    result.FinalizeCrud();
                    return(result);
                }
                // optimistic concurrency violation
                else
                {
                    if (forceMirroring)
                    {
                        var arguments = map.BuildExceptionReport(row.GetOriginalRKValues(), row.GetOriginalRowversionValue());
                        throw new QueryTalkException("Crud.UpdateGo", QueryTalkExceptionType.ConcurrencyViolation,
                                                     arguments, Text.Method.UpdateGo).SetObjectName(map.Name.Sql);
                    }
                    else
                    {
                        result.FinalizeCrud();
                        return(result);
                    }
                }
            }
            catch (QueryTalkException ex)
            {
                Loader.TryThrowInvalidSqlOperationException(ex, name, Text.Method.UpdateGo);
                throw;
            }
            catch (System.Exception ex)
            {
                var ex2 = Crud.ClrException(ex, name, Text.Method.UpdateGo);
                Loader.TryThrowInvalidSqlOperationException(ex2, name);
                throw ex2;
            }
        }