Save entity with Abstract Supertype

Posts   
 
    
jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 22-Jul-2011 12:09:13   

I have an inheritance structure :


  1
 /  \
2   3

where:
 1 = Relation (SuperType) Abstract
 2 = Contact (SubType) Concrete
 3 = Organization (SubType) Concrete

I'm using a Generic Repository:

public class LlblGenRepository<TEntity> : IRepository<TEntity> where TEntity : EntityBase2, IEntity2
{
...
}

Now I want to save a ContactEntity and get the error: "The given key was not present in the dictionary"

I think this exception raises because there is no RelationEntity created before the ContactEntity is created. Even when I try to Create the RelationEntity earlier (adapter.SaveEntity((RelationEntity)ContactEntity) it still tries to create the ContactEntity instead of the RelationEntity.

So my question is: How can I create/store an entity with an abstract supertype?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Jul-2011 00:53:46   

If you want to instantiate/save entities they shouldn't be abstract. What kind of inheritance do you have? and Why do you want RelationEntity to be abstract in the first place?

David Elizondo | LLBLGen Support Team
jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 25-Jul-2011 13:31:58   

I'm using a 'Target per entity' hierarchy.

The relation entity is general and contains fields which applies to both contacts and organizations. The relation enitty also contains the identifier, which is the pk-side for the fk in contact and organization.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jul-2011 16:23:27   

Which runtime library version (build no.) are you using?

jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 26-Jul-2011 09:15:26   

These are the libs i use:

SD.LLBLGen.Pro.ORMSupportClasses.NET20 - 3.1.11.527 SD.LLBLGen.Pro.LinqSupportClasses.NET35 - 3.1.11.518

The error i get wihle trying to save an concrete entity: "The given key was not present in the dictionary."

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jul-2011 09:38:41   

3.1.0.0 is not a correct build no.

Please follow the instructions here: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7722 Tot get the correct no. for both dlls.

jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 26-Jul-2011 10:46:02   

These are the libs i use:

SD.LLBLGen.Pro.ORMSupportClasses.NET20 - 3.1.11.527 SD.LLBLGen.Pro.LinqSupportClasses.NET35 - 3.1.11.518

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jul-2011 11:10:22   

That's strange.

The base entity should be inserted automatically before the child entity is saved. So normally you don't need to cast or pre-save the base entity. Just save the entity in question, and the framework do the plumbing for you.

So I don't know why this is not working with you. Could you please provide a simple repro solution including the llblgen project file.

jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 26-Jul-2011 11:25:27   

The strange thing is: I made a new project with the same hierarchy type and tried with a simple console app which worked fine.

Createing a console app in the project i'm working on, the error stays...

I've generated the code a couple of times which also doesn't help. It seems (in my opinion) the projectfile became "dirty". frowning

I'll try to reproduce it...

jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 26-Jul-2011 15:16:52   

Unfortunatly i can't reproduce it in another project.

I'm wondering which KeyValuePair is involved in the Save-action? What can i do more?

My StackTrace: at System.Collections.Generic.Dictionary2.get_Item(TKey key) at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateInsertDQ(IEntityFieldCore[] fields, IFieldPersistenceInfo[] fieldsPersistenceInfo, DbConnection connectionToUse) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\DynamicQueryEngineBase.cs:line 266 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateInsertDQ(IEntity2 entityToSave, IFieldPersistenceInfo[] persistenceInfoObjects) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 4397 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateQueryForEntityToSave(Boolean insertActions, IEntity2 entityToSave, IPredicateExpression updateRestriction, InheritanceHierarchyType typeOfHierarchy, IFieldPersistenceInfo[] persistenceInfoObjects) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5783 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PersistQueue(List1 queueToPersist, Boolean insertActions, Int32& totalAmountSaved) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1387 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, IPredicateExpression updateRestriction, Boolean recurse) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1316 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1141 at ...Data.Repositories.Llblgen.LlblGenRepository`1.Create(TEntity entityToCreate) in c:\projects\...Data.Repositories\Llblgen\LlblGenRepository.cs:line 175

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Jul-2011 20:28:43   

jwijnker wrote:

The strange thing is: I made a new project with the same hierarchy type and tried with a simple console app which worked fine.

Createing a console app in the project i'm working on, the error stays...

I've generated the code a couple of times which also doesn't help. It seems (in my opinion) the projectfile became "dirty". frowning

I'll try to reproduce it...

Mmmm :\ It might. Could you send us your .llblgenproj to examine it? You can open a HelpDesk thread (private) to attach your file.

David Elizondo | LLBLGen Support Team
jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 27-Jul-2011 15:05:04   

I created a new ProjectFile for my project and now it works as expected.

I stripped the old-one. Where/how can i send you the old one?