lundi 28 décembre 2015

Dapper and Sqlite: Insert list can't insert AI Primary key

public void InsertRates(IList<ExchangeRatePoco> rates, long exchangeBatchId)
    {
        using (var connection = new SqliteConnection(_configSettings.ConnectionString))
        {
            connection.Open();
            var rateQuery = $"INSERT INTO exchangerates VALUES (NULL,{exchangeBatchId},@CurrencyId,@Rate,@DateConversion);";
            try
            {
                connection.Execute(rateQuery, rates);
            }
            catch (Exception e)
            {
            }
        }
    }

I'm getting this exception: "{"Must add values for the following parameters: @CurrencyId, @Rate, @DateConversion"}".

I checked and data on rates is valid. Also this very same code (I just didn't include the NULL value for the PK) was working when I used to use Mysql instead of Sqlite.

Exchangerates table consists of 'ExchangeRateId','ExchangeBatchId','CurrencyId','Rate' and 'DateConversion'.

Aucun commentaire:

Enregistrer un commentaire