I have a problem trying to get records from a Sqlite table using Linq2db+SQLite, here is my table below
CREATE TABLE LogEntry
(
Time DATETIME NOT NULL ON CONFLICT ROLLBACK DEFAULT (CURRENT_TIMESTAMP),
Reference STRING NOT NULL ON CONFLICT ROLLBACK,
Team STRING,
Operator STRING,
ETMachine STRING,
CheckPoint BOOLEAN DEFAULT (0) NOT NULL
);
down is C# code:
using (var db = new DataConnection())
{
var newItem = new LogEntry()
{
CheckPoint = false,
ETMachine = "232323", // <= cause
Operator = "asdasd",
Reference = "asasas",
Team = "wewe",
Time = DateTime.Now
};
db.Insert<LogEntry>(newItem);
foreach (var item in db.LogEntries) //<= error occurs here
{
MessageBox.Show(string.Format("{0}:{1}", item.ID, item.Time));
}
}
and entity
[Table("LogEntry")]
public partial class LogEntry
{
[Column(Name = "ROWID"), NotNull, PrimaryKey, Identity] public int ID { get; set; } // datetime
[Column, NotNull ] public DateTime Time { get; set; } // datetime
[Column, NotNull ] public string Reference { get; set; } // string(max)
[Column, Nullable] public string Team { get; set; } // string(max)
[Column, Nullable] public string Operator { get; set; } // string(max)
[Column, Nullable] public string ETMachine { get; set; } // string(max)
[Column, NotNull ] public bool CheckPoint { get; set; } // boolean
}
I get
'System.InvalidCastException' occurred in System.Data.SQLite.dll
Additional information: Specified cast is not valid.
@ System.Data.SQLite.SQLiteDataReader.VerifyType(Int32 i, DbType typ)
@ System.Data.SQLite.SQLiteDataReader.GetString(Int32 i)
@ lambda_method(Closure , IDataReader )
@ LinqToDB.Expressions.ConvertFromDataReaderExpression.ColumnReader.GetValue(IDataReader dataReader) dans i:\linq2db\Source\Expressions\ConvertFromDataReaderExpression.cs:ligne 128
@ lambda_method(Closure , QueryContext , IDataContext , IDataReader , Expression , Object[] )
@ LinqToDB.Linq.Query`1.<Map>d__6a.MoveNext() dans i:\linq2db\Source\Linq\Query.cs:ligne 1218
@ Peel.FrmMain.Testdb2() dans C:\Users\Administrateur\Documents\Work\Projects\PeeL\src\Peel\FrmMain.cs:ligne 67
I searched a little bit and found out that the issue rises when a string field of the table have numeric values ex. ETMachine
property above, although the value is passed as string literal.
Here, if I change the 232323
to 232a323
it will work fine.
My question, How can I force Linq2db to insert the value as string and not numeric? Or, How can I force the Linq2DB to get values as its appropriate field type?
BTW target framework is 4.0.