SubmitChanges doesn't save but removes inserts from change set, no errors

Posted by winston schröder on Stack Overflow See other posts from Stack Overflow or by winston schröder
Published on 2010-04-01T13:18:54Z Indexed on 2010/04/01 13:23 UTC
Read the original article Hit count: 577

Filed under:
|
|

Hi Everybody,

I have a deeper question regarding debug functionality of Linq to Sql SubmitChanges() Function. I want to save a record in a table of a locally cached db (localdbcache: server SqlExpress 2008 client SqlCE). Before calling SubmitChanges I can find the new item via DataContext.GetChangeSet(). After calling Submit Changes, the items to insert have been removed from the ChangeSet. (That's what this function is supposed to do.) There are no Changes Conflicts and no error in the db's log output. No Exception at all. The table's Count stays at the same value.

if ((e.Parameter == null) || (!e.Parameter.GetType().Equals(typeof(LibDB.Client.Vehicles)))) return;
LibDB.Client.Vehicles tmp = e.Parameter as LibDB.Client.Vehicles;
        try
        {
            ChangeSet cs = this._dc.GetChangeSet();
            if ((tmp == null) || (this._dc == null)) return;
            if (this._dc.Vehicles.Where(veh => veh.Vin == tmp.Vin).Count() == 0)
                this._dc.Vehicles.InsertOnSubmit(tmp);
            else if (this._dc.Vehicles.Where(veh => veh.Vin == tmp.Vin).Count() == 1)
                this._dc.Vehicles.Attach(tmp, true);
            else
                return;
            using (TransactionScope ts = new TransactionScope())
            {
                try
                {                        
                    this._dc.SubmitChanges();
                    //this._dc.Refresh(RefreshMode.OverwriteCurrentValues, this._dc.Vehicles);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            if (this._dc.Vehicles.Where(veh => veh.Vin == tmp.Vin).Count() == 1)
                MessageBox.Show("Vehicle not saved.");
            this.vehSelector.ResetLayout();
        }

I would appreciate any help since I'm loosing hope to find any error, Thanks in Advance Winston

© Stack Overflow or respective owner

Related posts about submitchanges

Related posts about linq-to-sql