jonpryor / dblinq2007

Automatically exported from code.google.com/p/dblinq2007
0 stars 0 forks source link

InsertOnSubmit/SubmitChanges fails with cryptic exception if there is no primary key #225

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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

Original issue reported on code.google.com by ashm...@gmail.com on 6 Apr 2010 at 1:03

GoogleCodeExporter commented 9 years ago
Fixed owner/status.

Original comment by ashm...@gmail.com on 6 Apr 2010 at 1:04

GoogleCodeExporter commented 9 years ago
How to fix?? i got same problem.
Thanks a lot.

Original comment by alantang...@gmail.com on 18 May 2010 at 8:49

GoogleCodeExporter commented 9 years ago
Hello! I am still getting this problem with build 0.20.1. How do I fix it?

Original comment by sdoraisw...@gmail.com on 13 Aug 2010 at 12:03

GoogleCodeExporter commented 9 years ago
just create a primary key field for each of your table during your table 
creation.

Original comment by funnyk...@gmail.com on 1 Oct 2010 at 6:56

GoogleCodeExporter commented 9 years ago
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.

Original comment by pilichow...@gmail.com on 14 Feb 2011 at 8:33

GoogleCodeExporter commented 9 years ago
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. 

Original comment by daniel.t...@gmail.com on 16 Jun 2011 at 12:47

GoogleCodeExporter commented 9 years ago
I had the same issue and found that primary key which I initially had was 
dbgenerated which I later changed. But the file was still having DBGenerated: 
true.

Original comment by deepakrs...@gmail.com on 13 May 2013 at 1:42