Saving a derived object: The given key was not present in the dictionary

Posts   
 
    
Posts: 48
Joined: 14-Oct-2008
# Posted on: 16-Oct-2008 04:03:03   

I am using TargetPerEntity inheritance, and having a problem when I call the Save method on a constructed subtype. So for example,

A is the base type, B is the derived type

BEntity b = new BEntity();
b.BasePropertyFromA = 0;
b.DerivedProperty = 0;
b.Save();

When I call the Save() method I get a "KeyNotFoundException" saying "The given key was not present in the dictionary".

The same code works ok if I use the AEntity instead of BEntity and don't set the derived properties.

I'm not sure, but I'm wondering if this error is indicating that the PKID isn't placed in the database yet or isn't locatable somehow...

Any suggestions??

Version: 2.6 Final ( Sep 12, 2008 ) Model: SelfServicing Runtime: NET20 2.6.8.911 Database: MSSQL 2005

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Oct-2008 04:53:12   

Is the parent key a sequential field(s)? Please check this thread: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=11720

David Elizondo | LLBLGen Support Team
Posts: 48
Joined: 14-Oct-2008
# Posted on: 16-Oct-2008 04:58:35   

daelmo wrote:

Is the parent key a sequential field(s)? Please check this thread: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=11720

The parent key (and the object's key too, for that matter) is NOT a sequential field - it is a Guid. However, setting the SqlServerDQECompatibilityLevel to 2 seems to have worked nonetheless. Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Oct-2008 05:13:26   

Yep, for Guid is also necessary indeed. Rule of thumb: if you use SQL2K5, always set the compatibly level.

Good to know it worked wink

David Elizondo | LLBLGen Support Team