public void TestRemoveFisdNum()
        {
            var tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);

            DataBaseLink.DbLink dbLink         = new DbLink(tempConnection);
            fin_instrument      fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
            }

            var result = FinInstrument.FindId(dbLink, fin_instrument.ident);

            //fisd_id
            ffd ffd = new ffd()
            {
                ds_id  = 17,
                fi_id  = result.fi_id,
                fif_id = 11,
            };

            if (FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id) == null)
            {
                FFD.Insert(dbLink, ffd);
            }
            var ffdResult = FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id);

            fisd_num fisd_num = new fisd_num()
            {
                fisd_id  = ffdResult.fisd_id,
                dat_from = new DateTime(2018, 03, 24),
                val      = 320.0m
            };


            if (FisdNum.FindId(dbLink, ffdResult.fisd_id, fisd_num.dat_from) == null)
            {
                FisdNum.Insert(dbLink, fisd_num);
                var one = FisdNum.FindId(dbLink, fisd_num.fisd_id, fisd_num.dat_from);
                FisdNum.Remove(dbLink, fisd_num.fisd_id, fisd_num.dat_from);
            }
            else
            {
                FisdNum.Insert(dbLink, fisd_num);
                var one = FisdNum.FindId(dbLink, fisd_num.fisd_id, fisd_num.dat_from);
                FisdNum.Remove(dbLink, fisd_num.fisd_id, one.dat_from);
            }
        }
        //insert
        public static void Insert(DbLink dbLink, fisd_num fisd_num)
        {
            //при первой вставке дату указываем = 01.01.1900

            if (FindId(dbLink, fisd_num.fisd_id, fisd_num.dat_from) == null)
            {
                fisd_num.dat_from = new DateTime(1900, 01, 01);
            }
            else
            {
                var result = FindId(dbLink, fisd_num.fisd_id, fisd_num.dat_from);
                if (fisd_num.val == result.val)
                {
                    return;
                }
            }

            string query =
                @"insert into fisd_num(val, dat_from, fisd_id)
                    values(@val, @dat_from, @fisd_id)";

            dbLink.GetConnection().Execute(query, fisd_num);
        }
        private void Save(Dictionary <KeyValuePair <PortfolioPosition, Enum>, ScalarNum> storage)
        {
            foreach (var x in storage)
            {
                var transaction = _dbLink.GetConnection().BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    // найдем тип финансового инструмента
                    var    finIdent     = x.Key.Key.Ident;
                    var    finType      = x.Key.Key.FinType;
                    string finTypeIdent = _mapping.GetAI(finType);

                    #region финансовый инструмент
                    fin_instrument finInstrument = new fin_instrument()
                    {
                        ident = finIdent,
                        title = finIdent,
                        ft_id = int.Parse(finTypeIdent)
                    };

                    if (FinInstrument.FindId(_dbLink, finInstrument.ident) == null)
                    {
                        FinInstrument.Insert(_dbLink, finInstrument);
                    }

                    finInstrument = FinInstrument.FindId(_dbLink, finInstrument.ident);

                    #endregion

                    #region Data_source
                    data_source dataSource = new data_source()
                    {
                        ident = _providerParams[SCALAR].ToString(),
                    };

                    dataSource = DataSource.FindId(_dbLink, dataSource.ident);
                    #endregion

                    #region fisd_id
                    ffd ffd = new ffd()
                    {
                        ds_id  = dataSource.ds_id,
                        fi_id  = finInstrument.fi_id,
                        fif_id = int.Parse(_mapping.GetAI(x.Key.Value))
                    };

                    if (FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id) == null)
                    {
                        FFD.Insert(_dbLink, ffd);
                    }
                    ffd = FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id);
                    #endregion

                    fisd_num fisdNum = new fisd_num()
                    {
                        dat_from = x.Value.Dictionary.First().Key,
                        fisd_id  = ffd.fisd_id,
                        val      = x.Value.Dictionary.First().Value
                    };

                    FisdNum.Insert(_dbLink, fisdNum);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
            }
        }