SubmitChanges failure

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
dsdevoy
Posts: 9
Joined: Thu 29 Dec 2011 17:09

SubmitChanges failure

Post by dsdevoy » Sun 05 Aug 2012 21:15

Hi,
I have encountered a problem with the SubmitChanges method -- I have reduced the code and the schema to a bare minimum without discovering the nature of the problem.
With a db having a single (self-referential table), the InsertOnSubmit method does not actually ever issue an SQL INSERT command, and the table remains empty.

I am using VS2010, .NET 4.0 and Devart.Data.SQLite runtime version 2.0.50727.

Code: Select all

            using (PeopleDataContext db = PeopleDataContext.CreatePeopleContext(path, deleteExisting))
            {
                SQLiteMonitor DbMonitor = new SQLiteMonitor();
                DbMonitor.IsActive = true;

                /*** This code generates no error of any kind, but DbMonitor shows that the INSERT command
                 *   is never executed, and the Person collection remains empty.
                 *   
                Assert.AreEqual(0, db.People.Count());
                Person p = new Person();
                p.Name = "Nolo Contendre";
                db.People.InsertOnSubmit(p);
                db.SubmitChanges();
                  * **/

                /** This code performs the INSERT correctly, but loses the entire advantage of using
                 *  the higher level code. **/
                SQLiteConnection conn = db.Connection as SQLiteConnection;
                if (conn != null)
                {
                    conn.Open();
                    SQLiteTransaction tx = conn.BeginTransaction();
                    SQLiteCommand cmd = new SQLiteCommand(@"INSERT INTO Person VALUES(NULL,NULL,'Nolo Contendre')", conn);
                    cmd.ExecuteNonQuery();
                    tx.Commit();
                    conn.Close();
                }
                Assert.IsTrue(db.People.Count() == 1, "People count != 1");
            }
I can supply the entire solution and source db for the db-first code generation if that helps. Both are very small. This is very strange since I have other tables in other db's with identical structures that do not exhibit this behavior.
TIA.
--------------------------------------------------------------------------------

dsdevoy
Posts: 9
Joined: Thu 29 Dec 2011 17:09

Re: SubmitChanges failure

Post by dsdevoy » Mon 06 Aug 2012 13:31

Some further information.
The source db has the following structure:

Code: Select all

CREATE TABLE [Person] (
  [PK] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
  [ParentId] INTEGER CONSTRAINT [FKParent] REFERENCES [Person]([PK]) DEFAULT null, 
  [Name] VARCHAR NOT NULL ON CONFLICT FAIL);
And the DataContext is unmodified from the generated code using the Devart LinqConnect template.

dsdevoy
Posts: 9
Joined: Thu 29 Dec 2011 17:09

Re: SubmitChanges failure

Post by dsdevoy » Mon 06 Aug 2012 16:00

Nevermind. Operator error!!
I had implemented a partial datacontext class with null extensibility methods, including the insert method, on the incorrect assumption that doing so would have no effect on the default behavior. Slapping forehead now. :oops:

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SubmitChanges failure

Post by MariiaI » Tue 07 Aug 2012 07:51

Glad to see that the problem was resolved. If you have any further questions, feel free to contact us.

Post Reply