I am using SQLite
and System.Data.Linq.Mapping
. I am having a problem with the AUTOINCREMENT
id
AUTOINCREMENT
when using the linq display attribute IsDbGenerated = true
.
The syntax for creating my table. I tried this with / without AUTOINCREMENT
CREATE TABLE [TestTable] ([id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,[title] TEXT NULL)
My TABLE class:
[Table(Name = "TestTable")] public class TestTable { [Column(IsPrimaryKey = true, IsDbGenerated =true)] public int id { get; set; } [Column] public string title { get; set; } }
This is what I call it. When it is sent to submit, I get an error message, I will insert an error below this example. It is worth noting that if I pulled IsDbGenerated =true
above and enter id
manually, it inserts everything in order, but I would like it to be AUTOINCREMENT
, and for some reason IsDbGenerated=true
kills the insert. Looking for some guidance.
static void Main(string[] args) { string connectionString = @"DbLinqProvider=Sqlite;Data Source = c:\pathToDB\test.s3db"; SQLiteConnection connection = new SQLiteConnection(connectionString); DataContext db = new DataContext(connection); db.Log = new System.IO.StreamWriter(@"c:\pathToDB\mylog.log") { AutoFlush = true }; var com = db.GetTable<TestTable>(); com.InsertOnSubmit(new TestTable {title = "asdf2" }); try { db.SubmitChanges(); } catch(SQLiteException e) { Console.WriteLine(e.Data.ToString()); Console.WriteLine(e.ErrorCode); Console.WriteLine(e.HelpLink); Console.WriteLine(e.InnerException); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Console.WriteLine(e.TargetSite); Console.WriteLine(e.ToString()); } foreach (var TestTable in com) { Console.WriteLine("TestTable: {0} {1}", TestTable.id, TestTable.title); } Console.ReadKey(); }
Error message:
SQL logic error or missing database \ r \ nnear \ "SELECT \": syntax error
Stack trace:
in System.Data.SQLite.SQLite3.Prepare (SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String & strRemain) \ r \ n in System.Data.SQLite.SQLiteCommand.BuildNextCommand () \ r \ n on System. Data.SQLite.SQLiteCommand.GetStatement (index Int32) \ r \ n on System.Data.SQLite.SQLiteDataReader.NextResult () \ r \ n at System.Data.SQLite.SQLiteDataReader..ctor (SQLiteCommand cmd, CommandBehavior behave) \ r \ n at System.Data.SQLite.SQLiteCommand.ExecuteReader (CommandBehavior behavior) \ r \ n at System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader (CommandBehavior behavior \ r \ n in System.Data.Common.DbCommand.ExecuteReader ( ) \ r \ n
in System.Data.Linq.SqlClient.SqlProvider.Execute (expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object [] parentArgs, Object [] userArgs, ICompiledSubQuery [] subQueries, Object lastResult) \ r \ n at System.Data.Linq .SqlClient.SqlProvider.ExecuteAll (query expression, QueryInfo [] queryInfos, IObjectReaderFactory factory, Object [] userArguments, ICompiledSubQuery [] subQueries) \ r \ n on System.Data.Linq.SqlClient.SqlProvider.System.Data.ataPataL.D. .IProvider.Execute (Expression request) \ r \ n at System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicInsert (TrackedObject item) \ r \ n at System.Data.Linq.ChangeDirector.StandardChangeDirector.Insert (TrackedObject item) \ r \ n at System.Data.Linq.ChangeProcessor.SubmitChanges (ConflictMode failMode) \ r \ n in System.Data.Linq.DataContext.SubmitChanges (ConflictMode failMode) \ r \ n in System.Data.Linq.DataContext.SubmitChanges () \ r \ n in SqlLinq.Program.Main (String [] args) in Program.cs: page ok 29 "
Here is what I see in the output of the magazine:
INSERT INTO [company]([title]) VALUES (@p0) SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value] -- @p0: Input String (Size = 4000; Prec = 0; Scale = 0) [asdf2] -- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.6.81.0 SELECT [t0].[id], [t0].[title] FROM [company] AS [t0] -- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.6.81.0