views:

43

answers:

0

I have the following problem:

I have a transactions database that contains transactions. When inserting new transactions I need to check if they already exist. I then have a list of transactions that are new, and those need to be added to the database.

in code:

List<Transaction> allNewTransactions = Parse(rawDataInput); #count = 100
List<Transaction> verifiedTransactions = Verify(allNewTransactions);# count=5

foreach(Transaction transaction in verifiedTransactions)
{
    db.AddToTransaction(transaction);
}
db.saveChanges();

Strange thing is: It saves all my transactions to the database... Not just the verified ones.

Parse() is defined something like:

private List<Transaction> Parse(List<string> rawdataInput)
{
    List<Transaction> transactions = new List<Transaction>();
    Foreach(string rawdata in rawdataInput)
    { 
        Transaction transaction = new Transaction();
        transaction.value = rawdata;
        transactions.add(transaction);
    }
 }

I would almost think that creating a Transaction() makes it autoadding to the database, which is not true. However when I actively delete all the transactions that are duplicate, I get the wanted result:

db.DeleteObject(unwantedTransaction)

What am I missing here? Why do I need to delete all unwantedObjects, even when I didn't add them explicitly to the database by calling db.AddToTransaction()???