DataScope.Attach - how to know what is already in scope

Posts   
 
    
yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 26-Mar-2021 20:37:58   

LLBLGen 5.7.2 Adapters

If you attempt to add the same entity twice to the the DataScope you get an exception out of an internal Dictionary

    System.Private.CoreLib.dll!System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException<System.__Canon>(System.__Canon key)  Unknown
    System.Private.CoreLib.dll!System.Collections.Generic.Dictionary<System.Type, System.Collections.Generic.Dictionary<int, System.Collections.Generic.Dictionary<System.Guid, SD.LLBLGen.Pro.ORMSupportClasses.IEntityCore>>>.TryInsert(System.Type key, System.Collections.Generic.Dictionary<int, System.Collections.Generic.Dictionary<System.Guid, SD.LLBLGen.Pro.ORMSupportClasses.IEntityCore>> value, System.Collections.Generic.InsertionBehavior behavior)   Unknown
    System.Private.CoreLib.dll!System.Collections.Generic.Dictionary<System.__Canon, System.__Canon>.Add(System.__Canon key, System.__Canon value)  Unknown
    SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.Context.AddEntity(SD.LLBLGen.Pro.ORMSupportClasses.IEntityCore toAdd) Unknown
    SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.Context.Add<SD.LLBLGen.Pro.ORMSupportClasses.IEntityCore>(SD.LLBLGen.Pro.ORMSupportClasses.IEntityCore toAdd) Unknown
    SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.EntityCore<SD.LLBLGen.Pro.ORMSupportClasses.IEntityFields2>.ActiveContext.set(SD.LLBLGen.Pro.ORMSupportClasses.Context value) Unknown
    SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.EntityCore<SD.LLBLGen.Pro.ORMSupportClasses.IEntityFields2>.AddInternalsToContext(bool resetWhenNull) Unknown
    SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.EntityCore<SD.LLBLGen.Pro.ORMSupportClasses.IEntityFields2>.AddInternalsToContext(bool resetWhenNull) Unknown
    SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.Context.Add<SD.LLBLGen.Pro.ORMSupportClasses.IEntityCore>(SD.LLBLGen.Pro.ORMSupportClasses.IEntityCore toAdd) Unknown
    SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore<TheHub.Entities.EntityClasses.DocLinkEntity>.AddContainedEntitiesToContext()   Unknown
    SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore<System.__Canon>.ActiveContext.set(SD.LLBLGen.Pro.ORMSupportClasses.Context value)  Unknown
    SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.Context.Add(SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollectionCore toAdd) Unknown
    SD.LLBLGen.Pro.ORMSupportClasses.dll!SD.LLBLGen.Pro.ORMSupportClasses.DataScope.Attach(SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollectionCore toAttach) Unknown

I have some screens with complex ui, lots of tabs, slideouts, etc, where the data is loaded on demand and not all at the same time. Do I have to track what entities I have added to the scope so that if I load the same entity twice in 2 different graphs then when I Attach the graphs, I somehow remove those entities which are already in the scope?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 27-Mar-2021 10:30:51   

You don't have to attach entities if they're added to collections which are already tracked. You only have to call attach if you create an entity manually and it's not stored in a collection (e.g. if you add a CustomerEntity instance, and it has an Orders collection inside it, you can just add a new OrderEntity instance to that Orders collection and it's automatically tracked)

If your UI is very complex, it might be better to use multiple datascopes, e.g. 1 per screen (or groups of screens which all look at the same graph) ? The datascope uses a context so an entity can be in one scope at a time.

Frans Bouma | Lead developer LLBLGen Pro
yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 27-Mar-2021 16:28:16   

Thanks, that sounds good.