Whenever I try to insert a row into a table with a primary key set, it fails with the following very unhelpful exception:
Code: Select all
System.InvalidCastException was unhandled
Message="Specified cast is not valid."
Source="System.Data.Linq"
StackTrace:
at System.Data.Linq.Mapping.MetaAccessor`2.SetBoxedValue(Object& instance, Object value)
at Devart.Data.Linq.aa.e()
at Devart.Data.Linq.b.a()
at Devart.Data.Linq.y.a(DataContext A_0, ConflictMode A_1)
at Devart.Data.Linq.y.b(DataContext A_0, ConflictMode A_1)
at Devart.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at Devart.Data.Linq.DataContext.SubmitChanges()
at SqliteLinqTest.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Simon\Documents\Visual Studio 2008\Projects\SqliteLinqTest\SqliteLinqTest\Form1.cs:line 25
(Irrelevent stuff removed)
MyID, an integer PK with autoincrement
Text1, a nullable text field
If I remove autoincrement and set the ID manually, it has no effect. Changing whether it's nullable or not also has no effect. If I remove the PK, the exception goes away.
Here's the test code I'm using:
Code: Select all
MainDataContext dc = new MainDataContext();
TestTable tt = new TestTable();
tt.Text1 = "Some text";
dc.TestTables.InsertOnSubmit(tt);
dc.SubmitChanges();