1

I am trying to use SQLite in WinForms. So I created a table named Artist and it has 2 columns named ArtistId, Name. ArtistId's properties are: INTEGER PRIMARY AUTOINCREMENT.

In the foreach loop, if I give manually value, there is no problem.

    LtoSQLiteDataContext oc = new LtoSQLiteDataContext();
    int i = 1;
    foreach (var pdfs in articles)
    {
       var r = new PdfReader(pdfs);
       var title = r.Info["Title"].Trim();
       var m = new Artist
       {
                ArtistId = i,
                Name = title
        };
            oc.Artists.InsertOnSubmit(m);
            oc.SubmitChanges();
     i++;
     }

But if I ignore ArtistId like //ArtistId = i;, in the first record, ArtistId gets 0 and process is terminated. Here is screenshot: enter image description here

I know in MySQL and MsSQL, auto increment field's value is never written. Because it gets number in the sequence. I don't know, how auto increment poperty works correctly.

  • Read the [documentation](http://www.sqlite.org/autoinc.html). And show the actual table creation statement. – CL. Jan 03 '16 at 16:17
  • I read from beginning to end, but I did not understand much. My native language is not English, may be it is orginated this. Maybe it really confused. –  Jan 03 '16 at 17:22

1 Answers1

1

Make sure the generated code for the ArtistId property looks like this (open the *.Designer.cs file):

[Column(Name = @"ArtistId ", Storage = "_ArtistId", CanBeNull = false, DbType = "INTEGER NOT NULL", IsDbGenerated = true, IsPrimaryKey = true)]
   public long ArtistId 
   {...}

If not, please open your LinqConnect model and change the ArtistId property (open Properties for ArtistId property by double-clicking it):

  • set Entity Key = True
  • set Auto Generated Value = True
  • save the model.

If this doesn't help, please contact us with the test project (including LinqConnect model and test database file), so that we are able to investigate your scenario more clearly and find the solution for you in a shortest time.

Devart
  • 119,203
  • 23
  • 166
  • 186
  • I'm very sorry for the late thank.I have just taken care of this problem. Thank you very much. –  Feb 20 '16 at 23:10