New issue 225 by ashmind: InsertOnSubmit/SubmitChanges fails with cryptic
exception if there is no primary key
http://code.google.com/p/dblinq2007/issues/detail?id=225
What steps will reproduce the problem?
1. Create a table without a primary key (I used sqlite).
2. Use DBMetal to reflect the table in code as entity
3. InsertOnSubmit new instance of the entity
4. Call SubmitChanges
What is the expected output? What do you see instead?
Expected some kind of reasonable "no primary key" error on step 2 or 4.
Got:
[ArgumentNullException: Value cannot be null.
Parameter name: key]
System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument
argument) +44
System.Collections.Generic.Dictionary`2.FindEntry(TKey key) +7457585
System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue&
value) +16
DbLinq.Data.Linq.Implementation.EntityTracker.FindByIdentity(IdentityKey
identityKey) +24
DbLinq.Data.Linq.Implementation.EntityTracker.RegisterToWatch(Object
entity, IdentityKey identityKey) +35
DbLinq.Data.Linq.DataContext.MoveToAllTrackedEntities(Object entity,
Boolean insert) +156
DbLinq.Data.Linq.DataContext.InsertEntity(Object entity, QueryContext
queryContext) +68
DbLinq.Data.Linq.DataContext.SubmitChangesImpl(ConflictMode failureMode)
+574
DbLinq.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
+151
DbLinq.Data.Linq.DataContext.SubmitChanges() +9
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
Comment #1 on issue 225 by ashmind: InsertOnSubmit/SubmitChanges fails with
cryptic exception if there is no primary key
http://code.google.com/p/dblinq2007/issues/detail?id=225
Fixed owner/status.
Hello! I am still getting this problem with build 0.20.1. How do I fix it?
just create a primary key field for each of your table during your table
creation.
I can confirm it (with PostgreSQL) but I don't agree with original poster
stating "Expected some kind of reasonable "no primary key" error on step 2
or 4.".
This would be wrong as well. There is not a bug about message but behaviour
-- inserting records into table without primary key is valid operation and
it should work. Plain and simple.
The other story is corner case with update, when there is no chance to find
out what record (! singular) you are referring to.
I had the same issue and found out that one of my object properties had a
private setter. Once I changed the setter to public, this error went away.